mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-05-18 16:28:08 +00:00
20 lines
599 B
Rust
20 lines
599 B
Rust
use crate::routes::{health_check, subscribe};
|
|
use actix_web::dev::Server;
|
|
use actix_web::web::Data;
|
|
use actix_web::{web, App, HttpServer};
|
|
use sqlx::PgPool;
|
|
use std::net::TcpListener;
|
|
|
|
pub fn run(listener: TcpListener, db_pool: PgPool) -> Result<Server, std::io::Error> {
|
|
let db_pool = Data::new(db_pool);
|
|
let server = HttpServer::new(move || {
|
|
App::new()
|
|
.route("/health_check", web::get().to(health_check))
|
|
.route("/subscriptions", web::post().to(subscribe))
|
|
.app_data(db_pool.clone())
|
|
})
|
|
.listen(listener)?
|
|
.run();
|
|
Ok(server)
|
|
}
|