2020-04-06 08:38:08 +02:00
|
|
|
#![feature(async_closure)]
|
2020-05-05 22:56:55 +02:00
|
|
|
#![feature(vec_remove_item)]
|
2020-08-10 22:34:19 +02:00
|
|
|
#![recursion_limit = "256"]
|
2020-04-06 08:38:08 +02:00
|
|
|
|
2020-12-24 16:24:04 +01:00
|
|
|
use {
|
|
|
|
actix::Actor,
|
|
|
|
actix_web::{App, HttpServer},
|
|
|
|
};
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-03-27 16:17:25 +01:00
|
|
|
pub mod errors;
|
2020-12-24 16:24:04 +01:00
|
|
|
|
|
|
|
macro_rules! featured {
|
|
|
|
($app: ident, $feature: expr, $connect: expr) => {
|
|
|
|
#[cfg(feature = $feature)]
|
|
|
|
let $app = $connect;
|
|
|
|
};
|
|
|
|
}
|
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-12-24 16:24:04 +01:00
|
|
|
let web_config = jirs_config::web::Configuration::read();
|
2020-05-05 16:09:26 +02:00
|
|
|
|
2020-04-17 14:10:05 +02:00
|
|
|
let db_addr = actix::SyncArbiter::start(
|
2020-12-24 16:24:04 +01:00
|
|
|
jirs_config::database::Configuration::read().concurrency,
|
|
|
|
database_actor::DbExecutor::default,
|
2020-04-17 14:10:05 +02:00
|
|
|
);
|
|
|
|
let mail_addr = actix::SyncArbiter::start(
|
2020-12-24 16:24:04 +01:00
|
|
|
jirs_config::mail::Configuration::read().concurrency,
|
|
|
|
mail_actor::MailExecutor::default,
|
|
|
|
);
|
|
|
|
let hi_addr = actix::SyncArbiter::start(
|
|
|
|
jirs_config::hi::Configuration::read().concurrency,
|
|
|
|
highlight_actor::HighlightActor::default,
|
|
|
|
);
|
|
|
|
#[cfg(feature = "local-storage")]
|
2020-12-24 16:24:47 +01:00
|
|
|
let fs_addr = actix::SyncArbiter::start(
|
2020-12-24 16:24:04 +01:00
|
|
|
jirs_config::fs::Configuration::read().concurrency,
|
|
|
|
filesystem_actor::FileSystemExecutor::default,
|
2020-04-17 14:10:05 +02:00
|
|
|
);
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-12-24 16:24:04 +01:00
|
|
|
let ws_server = websocket_actor::server::WsServer::start_default();
|
2020-04-19 10:57:09 +02:00
|
|
|
|
2020-03-27 12:17:27 +01:00
|
|
|
HttpServer::new(move || {
|
2020-12-24 16:24:04 +01:00
|
|
|
let app = App::new().wrap(actix_web::middleware::Logger::default());
|
|
|
|
|
|
|
|
// data step
|
|
|
|
let app = app
|
2020-12-24 16:24:47 +01:00
|
|
|
.data(ws_server.clone())
|
|
|
|
.data(db_addr.clone())
|
|
|
|
.data(mail_addr.clone())
|
|
|
|
.data(hi_addr.clone())
|
|
|
|
.data(database_actor::build_pool());
|
|
|
|
featured! { app, "local-storage", app.data(fs_addr.clone()) };
|
2020-12-24 16:24:04 +01:00
|
|
|
|
|
|
|
// services step
|
|
|
|
let app = app
|
2020-12-24 16:24:47 +01:00
|
|
|
.service(websocket_actor::index)
|
|
|
|
.service(actix_web::web::scope("/avatar").service(web_actor::avatar::upload));
|
2020-05-05 16:09:26 +02:00
|
|
|
|
2020-12-24 16:24:47 +01:00
|
|
|
featured! { app, "local-storage", app.service(filesystem_actor::service()) };
|
2020-05-05 08:33:40 +02:00
|
|
|
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(())
|
|
|
|
}
|