db pool and address

This commit is contained in:
LinlyBoi
2023-12-17 22:12:59 +02:00
parent 3fbb68d349
commit 33074b4c6b

View File

@@ -1,6 +1,6 @@
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder}; use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
use dotenv::dotenv; use dotenv::dotenv;
use witl_api::*;
#[post("/echo")] #[post("/echo")]
async fn echo(req_body: String) -> impl Responder { async fn echo(req_body: String) -> impl Responder {
HttpResponse::Ok().body(req_body) HttpResponse::Ok().body(req_body)
@@ -13,11 +13,12 @@ async fn manual_hello() -> impl Responder {
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
dotenv().ok(); dotenv().ok();
let (port, address) = init_address();
HttpServer::new(|| { HttpServer::new(|| {
App::new() App::new()
.service(hello) .service(hello)
.service(echo) .service(echo)
.route("/hey", web::get().to(manual_hello)) .app_data(web::Data::new(init_dbpool()))
}) })
.bind(("localhost", 8080))? .bind(("localhost", 8080))?
.run() .run()