Files
gamenight/backend-actix/src/main.rs

69 lines
2.5 KiB
Rust

#[allow(unused_imports)]
pub mod models;
pub mod request;
use actix_cors::Cors;
use actix_web::http;
use actix_web::middleware::Logger;
use actix_web::web;
use actix_web::App;
use actix_web::HttpServer;
use gamenight_database::{get_connection_pool, run_migration, GetConnection};
use request::*;
use tracing_actix_web::TracingLogger;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let url = "postgres://root:root@127.0.0.1/gamenight";
let pool = get_connection_pool(url);
let mut conn = pool.get_conn();
run_migration(&mut conn);
env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug"));
HttpServer::new(move || {
let cors = Cors::default()
.allowed_origin("0.0.0.0")
.allowed_origin_fn(|_origin, _req_head| true)
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
.allowed_header(http::header::CONTENT_TYPE)
.max_age(3600);
App::new()
.wrap(cors)
.wrap(Logger::default())
.wrap(TracingLogger::default())
.app_data(web::Data::new(pool.clone()))
.service(token::post_token)
.service(token::post_refresh_token)
.service(users::get_users)
.service(users::post_users)
.service(user::get_user)
.service(user_owned_games::get_user_owned_games)
.service(gamenights::get_gamenights)
.service(gamenights::post_gamenights)
.service(gamenight::get_gamenight)
.service(gamenight_participants::get_gamenight_participants)
.service(gamenight_participants::post_gamenight_participants)
.service(gamenight_participant::delete_gamenight_participant)
.service(games::get_games)
.service(games::post_games)
.service(game::get_game)
.service(game::delete_game)
.service(game::put_game)
.service(game_owners::post_game_owners)
.service(game_owner::delete_game_owner)
.service(locations::get_locations)
.service(locations::post_locations)
.service(location_authorized_users::get_location_authorized_users)
.service(location_authorized_users::post_location_authorized_users)
.service(location_authorized_user::delete_location_authorized_user)
})
.bind(("::1", 8080))?
.run()
.await
}