-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
60 lines (53 loc) · 1.39 KB
/
main.rs
File metadata and controls
60 lines (53 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
mod config;
mod db;
mod error;
mod handlers;
mod models;
mod param;
mod routes;
mod state;
mod templates;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{
App,
HttpServer,
middleware::Logger,
};
use actix_identity::{
CookieIdentityPolicy,
IdentityService,
};
use actix_cors::Cors;
use crate::routes;
use dotenv::dotenv;
use tokio_postgres::NoTls;
use std::env;
std::env::set_var("RUST_LOG", "actix_web=debug");
env_logger::init();
dotenv().ok();
let config = config::Config::from_env().unwrap();
let pool = config.pg.create_pool(NoTls).unwrap();
let port = env::var("PORT")
.unwrap_or_else(|_| "8080".to_string())
.parse()
.expect("PORT must be a number.");
let server = HttpServer::new(move || {
let cors = Cors::permissive(); // FIXME
App::new()
.wrap(Logger::default())
.wrap(IdentityService::new(
CookieIdentityPolicy::new(&[0; 32])
.name("auth-cookie")
.secure(false)))
.wrap(cors)
.data(pool.clone())
.configure(routes::app_config)
})
.bind((config.server_addr.clone(), port))?
.run();
println!("Server running at http://{}:{}/",
config.server_addr,
port);
server.await
}