FrostByte/server/src/main.rs

42 lines
1.1 KiB
Rust
Raw Normal View History

use actix_files::Files;
use actix_web::middleware;
2023-10-10 19:45:18 +02:00
use actix_web::web::Data;
2023-10-09 19:21:55 +02:00
use actix_web::{web::scope, App, HttpServer};
2023-10-10 00:03:04 +02:00
use log::info;
2023-10-09 19:21:55 +02:00
2023-10-10 17:12:47 +02:00
mod jwt;
2023-10-09 19:21:55 +02:00
mod routes;
2023-10-10 00:03:04 +02:00
mod state;
2023-10-09 19:21:55 +02:00
mod types;
2023-10-10 17:12:47 +02:00
use routes::{get_posts, login, new_post, register, test};
2023-10-10 00:03:04 +02:00
use state::AppState;
2023-10-09 19:21:55 +02:00
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug")).init();
2023-10-10 00:03:04 +02:00
let data = AppState::new().await;
2023-10-09 19:21:55 +02:00
2023-10-10 00:03:04 +02:00
info!("Spinning up server on http://localhost:8080");
2023-10-09 19:21:55 +02:00
HttpServer::new(move || {
App::new()
.wrap(middleware::Compress::default())
.wrap(middleware::Logger::default())
.service(
scope("/api")
.service(get_posts)
.service(new_post)
.service(routes::vote)
.service(test)
.service(login)
.service(register)
.app_data(Data::new(data.clone())),
)
.service(Files::new("/", "./public").index_file("index.html"))
2023-10-09 19:21:55 +02:00
})
.bind("0.0.0.0:8080")?
2023-10-09 19:21:55 +02:00
.run()
.await
}