gamenight/backend-actix/src/main.rs

35 lines
929 B
Rust

pub mod request;
pub mod schema;
use actix_web::HttpServer;
use actix_web::App;
use actix_web::web;
use diesel::PgConnection;
use request::{login, register};
use diesel::r2d2::ConnectionManager;
use diesel::r2d2::Pool;
pub(crate) type DbPool = Pool<ConnectionManager<PgConnection>>;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let url = "postgres://root:root@localhost/gamenight";
let manager = ConnectionManager::<PgConnection>::new(url);
// Refer to the `r2d2` documentation for more methods to use
// when building a connection pool
let pool = Pool::builder()
.test_on_check_out(true)
.build(manager)
.expect("Could not build connection pool");
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(pool.clone()))
.service(login)
.service(register)
})
.bind(("::1", 8080))?
.run()
.await
}