40 lines
1.0 KiB
Rust
40 lines
1.0 KiB
Rust
use std::env;
|
|
|
|
use actix_identity::IdentityMiddleware;
|
|
use actix_session::{storage::CookieSessionStore, SessionMiddleware};
|
|
use actix_web::cookie::Key;
|
|
use actix_web::{web, App, HttpServer};
|
|
use dotenv::dotenv;
|
|
use sqlx::postgres::PgPool;
|
|
|
|
mod auth;
|
|
mod calendar;
|
|
mod models;
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
dotenv()?;
|
|
let pool = PgPool::connect(&env::var("DATABASE_URL")?).await?;
|
|
let secret_key = Key::generate();
|
|
|
|
println!("Starting server on http://localhost:8080.");
|
|
|
|
HttpServer::new(move || {
|
|
App::new()
|
|
.app_data(web::Data::new(pool.clone()))
|
|
.configure(auth::init)
|
|
.configure(calendar::init)
|
|
.wrap(IdentityMiddleware::default())
|
|
.wrap(SessionMiddleware::new(
|
|
CookieSessionStore::default(),
|
|
secret_key.clone(),
|
|
))
|
|
.service(actix_files::Files::new("", "./static").show_files_listing())
|
|
})
|
|
.bind(("127.0.0.1", 8080))?
|
|
.run()
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|