FrostByte/server/src/main.rs

41 lines
1.1 KiB
Rust
Executable file

use actix_files::Files;
use actix_web::middleware;
use actix_web::web::Data;
use actix_web::{web::scope, App, HttpServer};
use log::info;
mod jwt;
mod routes;
mod state;
mod types;
use routes::{get_posts, login, new_post, register, test};
use state::AppState;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug")).init();
let data = AppState::new().await;
info!("Spinning up server on http://localhost:8080");
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"))
})
.bind("localhost:8080")?
.run()
.await
}