-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup.rs
26 lines (23 loc) · 877 Bytes
/
startup.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use crate::routes::{health_check, subscribe};
use actix_web::dev::Server;
use actix_web::{web, App, HttpServer};
use sqlx::PgPool;
use std::net::TcpListener;
use tracing_actix_web::TracingLogger;
// `async` is no longer needed as we don't have .await calls.
pub fn run(listener: TcpListener, db_pool: PgPool) -> Result<Server, std::io::Error> {
// create a ARC pointer to the DB connection
let db_pool = web::Data::new(db_pool);
let server = HttpServer::new(move || {
App::new()
.wrap(TracingLogger::default())
// .route("/", web::get().to(greet))
// .route("/{name}", web::get().to(greet))
.route("/health_check", web::get().to(health_check))
.route("/subscriptions", web::post().to(subscribe))
.app_data(db_pool.clone())
})
.listen(listener)?
.run();
Ok(server)
}