zero-to-production/chapter05/src/startup.rs
Luca Palmieri 0a4addc6bb
Chapter 5 (#13)
* Add chapter 5

* Basic deployment stuff

* Fix Dockerfile.

* Add an explicit connection timeout.

* Align port with configuration.

* Use debug for faster feedback loops.

* Add address configuration.

* Provision database.

* Use structured options.

* Add configuration

* Fix typo.

* Customise deserialization logic.

* Change to Require.

* Fix spec.

* Add a few more things to the dockerignore file.

* Update to match chapter.

* Add base configuration.

* Amend configuratiohn.

Co-authored-by: LukeMathWalker <rust@lpalmieri.com>
2020-11-01 21:25:11 +00:00

22 lines
670 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;
use tracing_actix_web::TracingLogger;
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()
.wrap(TracingLogger)
.route("/health_check", web::get().to(health_check))
.route("/subscriptions", web::post().to(subscribe))
.app_data(db_pool.clone())
})
.listen(listener)?
.run();
Ok(server)
}