bitque/jirs-server/src/main.rs

76 lines
2.1 KiB
Rust
Raw Normal View History

2020-04-06 08:38:08 +02:00
#![feature(async_closure)]
#![feature(vec_remove_item)]
2020-08-10 22:34:19 +02:00
#![recursion_limit = "256"]
2020-04-06 08:38:08 +02: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;
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
let web_config = jirs_config::web::Configuration::read();
2020-05-05 16:09:26 +02:00
let db_addr = actix::SyncArbiter::start(
jirs_config::database::Configuration::read().concurrency,
database_actor::DbExecutor::default,
);
let mail_addr = actix::SyncArbiter::start(
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")]
let fs_addr = actix::SyncArbiter::start(
jirs_config::fs::Configuration::read().concurrency,
filesystem_actor::FileSystemExecutor::default,
);
2020-03-27 12:17:27 +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 || {
let app = App::new().wrap(actix_web::middleware::Logger::default());
// data step
let app = app
.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()) }
;
// services step
let app = app
.service(websocket_actor::index)
.service(actix_web::web::scope("/avatar").service(web_actor::avatar::upload));
2020-05-05 16:09:26 +02: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
})
.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(())
}