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
61
62
63
64
65
66
67
|
mod config;
mod db;
mod errors;
mod helpers;
mod git;
mod branch;
mod commit;
mod email;
mod repository;
use actix_cors::Cors;
use actix_web::{http::header, middleware, App, HttpServer};
use dotenv::dotenv;
use slog::info;
use std::env;
use tokio_postgres::NoTls;
use crate::config::{AppState, Config};
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
dotenv().ok();
let config = Config::from_env().unwrap();
let pool = config.pg.create_pool(NoTls).unwrap();
let log = Config::logging();
info!(
log,
"Starting server at http://{}:{}",
config.server.host,
config.server.port
);
HttpServer::new(move || {
App::new()
.data(AppState {
pool: pool.clone(),
log: log.clone(),
})
.wrap(middleware::Logger::default())
.wrap(
Cors::default()
.allowed_origin(
&env::var("CLIENT")
.unwrap_or("http://localhost:8080".to_string())[..]
)
.allowed_methods(vec!["GET", "POST", "DELETE"])
.allowed_headers(vec![
header::AUTHORIZATION,
header::ACCEPT,
])
.allowed_header(header::CONTENT_TYPE)
.supports_credentials()
.max_age(3600),
)
.configure(repository::routes::config)
.configure(email::routes::config)
.configure(commit::routes::config)
.configure(branch::routes::config)
})
.bind(format!("{}:{}", config.server.host, config.server.port))?
.run()
.await
}
|