mirror of
https://github.com/actix/examples
synced 2025-06-27 01:27:43 +02:00
standardize examples
This commit is contained in:
@ -4,10 +4,7 @@ extern crate diesel;
|
||||
use actix_identity::IdentityMiddleware;
|
||||
use actix_session::{config::PersistentSession, storage::CookieSessionStore, SessionMiddleware};
|
||||
use actix_web::{cookie::Key, middleware, web, App, HttpServer};
|
||||
use diesel::{
|
||||
prelude::*,
|
||||
r2d2::{self, ConnectionManager},
|
||||
};
|
||||
use diesel::{prelude::*, r2d2};
|
||||
use time::Duration;
|
||||
|
||||
mod auth_handler;
|
||||
@ -22,21 +19,19 @@ mod utils;
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
std::env::set_var(
|
||||
"RUST_LOG",
|
||||
"simple-auth-server=debug,actix_web=info,actix_server=info",
|
||||
);
|
||||
env_logger::init();
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||
|
||||
// create db connection pool
|
||||
let manager = ConnectionManager::<PgConnection>::new(database_url);
|
||||
let manager = r2d2::ConnectionManager::<PgConnection>::new(database_url);
|
||||
let pool: models::Pool = r2d2::Pool::builder()
|
||||
.build(manager)
|
||||
.expect("Failed to create pool.");
|
||||
let domain: String = std::env::var("DOMAIN").unwrap_or_else(|_| "localhost".to_string());
|
||||
|
||||
// Start http server
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.app_data(web::Data::new(pool.clone()))
|
||||
|
Reference in New Issue
Block a user