restructured, added db connection pool
This commit is contained in:
20
src/startup.rs
Normal file
20
src/startup.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use actix_web::dev::Server;
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use sqlx::{Pool, Postgres};
|
||||
use std::net::TcpListener;
|
||||
|
||||
use crate::routes::{health_check, subscribe};
|
||||
|
||||
pub fn run(listener: TcpListener, connection: Pool<Postgres>) -> Result<Server, std::io::Error> {
|
||||
let connection = web::Data::new(connection);
|
||||
let server = HttpServer::new(move || {
|
||||
App::new()
|
||||
.route("/health_check", web::get().to(health_check))
|
||||
.route("/subscriptions", web::post().to(subscribe))
|
||||
.app_data(connection.clone())
|
||||
})
|
||||
.listen(listener)?
|
||||
.run();
|
||||
|
||||
Ok(server)
|
||||
}
|
||||
Reference in New Issue
Block a user