60 lines
1.5 KiB
Rust
60 lines
1.5 KiB
Rust
mod cases;
|
|
mod items;
|
|
mod types;
|
|
mod users;
|
|
mod utils;
|
|
|
|
use cases::*;
|
|
use items::*;
|
|
use users::*;
|
|
use utils::*;
|
|
|
|
use actix_web::web::Data;
|
|
use actix_web::{App, HttpServer, middleware::DefaultHeaders};
|
|
use sqlx::sqlite::SqlitePool;
|
|
|
|
#[derive(Clone)]
|
|
struct AppState {
|
|
database: SqlitePool,
|
|
jwt_token_expiration: u64,
|
|
refresh_token_expiration: u64,
|
|
allow_origins: Vec<&'static str>,
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
let pool = SqlitePool::connect("sqlite:database.db")
|
|
.await
|
|
.expect("Could not connect to db");
|
|
let app_state = Data::new(AppState {
|
|
database: pool,
|
|
jwt_token_expiration: 60,
|
|
refresh_token_expiration: 86400,
|
|
allow_origins: vec!["http://localhost:5173"],
|
|
});
|
|
HttpServer::new(move || {
|
|
App::new()
|
|
.wrap(
|
|
DefaultHeaders::new()
|
|
.add((
|
|
"Access-Control-Allow-Origin",
|
|
app_state.allow_origins.join(","),
|
|
))
|
|
.add(("Access-Control-Allow-Credentials", "true")),
|
|
)
|
|
.service(login)
|
|
.service(logout)
|
|
.service(get_case)
|
|
.service(get_cases)
|
|
.service(get_item)
|
|
.service(get_items)
|
|
.service(get_case_items)
|
|
.service(get_item_cases)
|
|
.service(options)
|
|
.app_data(app_state.clone())
|
|
})
|
|
.bind(("127.0.0.1", 8000))?
|
|
.run()
|
|
.await
|
|
}
|