32 lines
943 B
Rust
32 lines
943 B
Rust
use std::io;
|
|
|
|
use actix_web::{App, HttpServer, middleware, web};
|
|
|
|
pub mod services;
|
|
pub mod state;
|
|
pub mod static_app_data;
|
|
|
|
/// Leaks memory for the sake of not atomic'ing all over.
|
|
#[expect(clippy::missing_errors_doc)]
|
|
pub async fn start_app(state: &'static state::AppState) -> io::Result<()> {
|
|
use crate::consts::web_scopes as ws;
|
|
|
|
println!(
|
|
"\x1b[34mINF\x1b[0m: Trying to listen on \x1b[35m{:?}\x1b[0m",
|
|
state.config.server.listen
|
|
);
|
|
|
|
HttpServer::new(move || {
|
|
App::new()
|
|
.app_data(state)
|
|
.wrap(middleware::Logger::new("%a (%{r}a) %r -> %s, %b B in %T s"))
|
|
.wrap(middleware::NormalizePath::trim())
|
|
.service(services::images::make_scope(ws::IMAGES))
|
|
.service(services::login::make_scope(ws::LOGIN))
|
|
.default_service(web::to(services::not_found::not_found))
|
|
})
|
|
.bind(&state.config.server.listen)?
|
|
.run()
|
|
.await
|
|
}
|