Started reimplementation of the Rest api in actix-web

This commit is contained in:
2023-03-17 22:19:10 +01:00
parent 7741c1dbae
commit d961896242
12 changed files with 2247 additions and 0 deletions

35
backend-actix/src/main.rs Normal file
View File

@@ -0,0 +1,35 @@
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
}