2020-04-06 08:38:08 +02:00
|
|
|
#![feature(async_closure)]
|
|
|
|
|
2020-03-27 12:17:27 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
2020-04-03 14:29:30 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-04-19 10:57:09 +02:00
|
|
|
use actix::Actor;
|
2020-03-27 12:17:27 +01:00
|
|
|
use actix_cors::Cors;
|
2020-05-05 08:33:40 +02:00
|
|
|
use actix_files as fs;
|
2020-04-17 14:10:05 +02:00
|
|
|
use actix_web::{App, HttpServer};
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-04-19 10:57:09 +02:00
|
|
|
use crate::ws::WsServer;
|
|
|
|
|
2020-03-27 12:17:27 +01:00
|
|
|
pub mod db;
|
2020-03-27 16:17:25 +01:00
|
|
|
pub mod errors;
|
2020-04-17 14:10:05 +02:00
|
|
|
pub mod mail;
|
2020-03-27 12:17:27 +01:00
|
|
|
pub mod middleware;
|
|
|
|
pub mod models;
|
|
|
|
pub mod schema;
|
2020-04-19 10:57:09 +02:00
|
|
|
pub mod utils;
|
2020-04-17 14:10:05 +02:00
|
|
|
pub mod web;
|
2020-04-05 15:15:09 +02:00
|
|
|
pub mod ws;
|
2020-03-27 12:17:27 +01:00
|
|
|
|
|
|
|
#[actix_rt::main]
|
|
|
|
async fn main() -> Result<(), String> {
|
|
|
|
dotenv::dotenv().ok();
|
2020-04-03 14:29:30 +02:00
|
|
|
pretty_env_logger::init();
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-04-17 14:10:05 +02:00
|
|
|
let web_config = web::Configuration::read();
|
2020-03-30 14:26:25 +02:00
|
|
|
|
2020-04-17 14:10:05 +02:00
|
|
|
let db_addr = actix::SyncArbiter::start(
|
|
|
|
crate::db::Configuration::read().concurrency,
|
|
|
|
crate::db::DbExecutor::default,
|
|
|
|
);
|
|
|
|
let mail_addr = actix::SyncArbiter::start(
|
|
|
|
crate::mail::Configuration::read().concurrency,
|
|
|
|
crate::mail::MailExecutor::default,
|
|
|
|
);
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-04-19 10:57:09 +02:00
|
|
|
let ws_server = WsServer::default().start();
|
|
|
|
|
2020-03-27 12:17:27 +01:00
|
|
|
HttpServer::new(move || {
|
2020-05-05 08:33:40 +02:00
|
|
|
let web_config = web::Configuration::read();
|
|
|
|
let mut app = App::new()
|
2020-03-27 12:17:27 +01:00
|
|
|
.wrap(actix_web::middleware::Logger::default())
|
|
|
|
.wrap(Cors::default())
|
2020-04-19 10:57:09 +02:00
|
|
|
.data(ws_server.clone())
|
2020-03-27 12:17:27 +01:00
|
|
|
.data(db_addr.clone())
|
2020-04-17 14:10:05 +02:00
|
|
|
.data(mail_addr.clone())
|
2020-03-27 16:17:25 +01:00
|
|
|
.data(crate::db::build_pool())
|
2020-04-05 15:15:09 +02:00
|
|
|
.service(crate::ws::index)
|
2020-05-05 08:33:40 +02:00
|
|
|
.service(actix_web::web::scope("/avatar").service(crate::web::avatar::upload));
|
|
|
|
if let Some(file_system) = web_config.filesystem.as_ref() {
|
|
|
|
app = app.service(fs::Files::new(
|
|
|
|
file_system.client_path.as_str(),
|
|
|
|
file_system.store_path.as_str(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
app
|
2020-03-27 12:17:27 +01:00
|
|
|
})
|
2020-04-17 14:10:05 +02:00
|
|
|
.workers(web_config.concurrency)
|
|
|
|
.bind(web_config.addr())
|
2020-03-27 12:17:27 +01:00
|
|
|
.map_err(|e| format!("{}", e))?
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
.expect("Server internal error");
|
|
|
|
Ok(())
|
|
|
|
}
|