2022-02-04 19:36:54 +00:00
|
|
|
use actix_web::{web, App, HttpServer};
|
2022-02-03 21:55:10 +00:00
|
|
|
use sea_orm::{Database, DatabaseConnection};
|
2022-02-04 19:36:54 +00:00
|
|
|
use tracing::{info, instrument};
|
2022-02-03 21:55:10 +00:00
|
|
|
use tracing_subscriber::prelude::*;
|
|
|
|
|
|
|
|
mod api;
|
|
|
|
mod entity;
|
2022-02-04 19:36:54 +00:00
|
|
|
mod error;
|
2022-02-03 21:55:10 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct AppState {
|
|
|
|
pub db: DatabaseConnection,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() {
|
|
|
|
let subscriber = tracing_subscriber::registry().with(
|
|
|
|
tracing_subscriber::fmt::Layer::new()
|
|
|
|
.pretty()
|
|
|
|
.with_writer(std::io::stdout)
|
|
|
|
.with_ansi(true)
|
|
|
|
.with_filter(tracing_subscriber::filter::LevelFilter::DEBUG),
|
|
|
|
);
|
|
|
|
tracing::subscriber::set_global_default(subscriber).expect("Unable to set a global collector");
|
|
|
|
|
|
|
|
let db = setup_database().await.unwrap();
|
2022-02-04 19:36:54 +00:00
|
|
|
let state = web::Data::new(AppState { db });
|
2022-02-03 21:55:10 +00:00
|
|
|
|
|
|
|
info!("Starting http server on 8080");
|
|
|
|
HttpServer::new(move || {
|
|
|
|
App::new()
|
|
|
|
.app_data(state.clone())
|
2022-02-04 19:36:54 +00:00
|
|
|
.service(api::applications::routes())
|
|
|
|
.service(api::application_category::routes())
|
2022-02-03 21:55:10 +00:00
|
|
|
})
|
|
|
|
.bind("127.0.0.1:8080")
|
|
|
|
.unwrap()
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
.expect("Couldnt launch server");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[instrument]
|
|
|
|
async fn setup_database() -> Result<DatabaseConnection, sea_orm::DbErr> {
|
|
|
|
Database::connect("sqlite://data.db").await
|
|
|
|
}
|