Matthieu Bessat
3713cc2443
Created a kernel crate to store models and future action implementations. Will be useful to create admin cli.
67 lines
1.5 KiB
Rust
67 lines
1.5 KiB
Rust
pub mod controllers;
|
|
pub mod router;
|
|
pub mod services;
|
|
pub mod middlewares;
|
|
pub mod renderer;
|
|
pub mod token_claims;
|
|
|
|
use fully_pub::fully_pub;
|
|
use anyhow::{Result, Context};
|
|
use kernel::{context::AppSecrets, models::config::Config, repositories::storage::Storage};
|
|
use log::info;
|
|
use minijinja::Environment;
|
|
|
|
use crate::{
|
|
router::build_router,
|
|
renderer::build_templating_env
|
|
};
|
|
|
|
pub const WEB_GUI_JWT_COOKIE_NAME: &str = "minauthator_jwt";
|
|
|
|
#[derive(Debug)]
|
|
#[fully_pub]
|
|
/// HTTP server arguments
|
|
pub struct ServerConfig {
|
|
listen_host: String,
|
|
listen_port: u32,
|
|
assets_path: String
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
#[fully_pub]
|
|
pub struct AppState {
|
|
secrets: AppSecrets,
|
|
config: Config,
|
|
db: Storage,
|
|
templating_env: Environment<'static>
|
|
}
|
|
|
|
pub async fn start_http_server(
|
|
server_config: ServerConfig,
|
|
config: Config,
|
|
secrets: AppSecrets,
|
|
db_pool: Storage
|
|
) -> Result<()> {
|
|
// build state
|
|
let state = AppState {
|
|
templating_env: build_templating_env(&config),
|
|
config,
|
|
secrets,
|
|
db: db_pool
|
|
};
|
|
|
|
// build routes
|
|
let services = build_router(
|
|
&server_config,
|
|
state.clone()
|
|
)
|
|
.with_state(state);
|
|
|
|
let listen_addr = format!("{}:{}", server_config.listen_host, server_config.listen_port);
|
|
info!("Starting web server on http://{}", &listen_addr);
|
|
let listener = tokio::net::TcpListener::bind(listen_addr).await.unwrap();
|
|
|
|
axum::serve(listener, services).await.context("Axum serve")?;
|
|
|
|
Ok(())
|
|
}
|