email with token & confirmation works
This commit is contained in:
@ -5,22 +5,26 @@ use tracing_actix_web::TracingLogger;
|
||||
use std::net::TcpListener;
|
||||
|
||||
use crate::email_client::EmailClient;
|
||||
use crate::routes::{health_check, subscribe};
|
||||
use crate::routes::{confirm, health_check, subscribe};
|
||||
|
||||
pub fn run(
|
||||
listener: TcpListener,
|
||||
connection_pool: Pool<Postgres>,
|
||||
email_client: EmailClient,
|
||||
base_url: String,
|
||||
) -> Result<Server, std::io::Error> {
|
||||
let connection_pool = web::Data::new(connection_pool);
|
||||
let email_client = web::Data::new(email_client);
|
||||
let base_url = web::Data::new(ApplicationBaseUrl(base_url));
|
||||
let server = HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(TracingLogger::default())
|
||||
.route("/health_check", web::get().to(health_check))
|
||||
.route("/subscriptions", web::post().to(subscribe))
|
||||
.route("/subscriptions/confirm", web::get().to(confirm))
|
||||
.app_data(connection_pool.clone())
|
||||
.app_data(email_client.clone())
|
||||
.app_data(base_url.clone())
|
||||
})
|
||||
.listen(listener)?
|
||||
.run();
|
||||
@ -50,7 +54,7 @@ impl Application {
|
||||
|
||||
let listener = TcpListener::bind(format!("{}:{}", config.application.host, config.application.port))?;
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
let server = run(listener, connection_pool, email_client)?;
|
||||
let server = run(listener, connection_pool, email_client, config.application.base_url)?;
|
||||
Ok(Self { port, server })
|
||||
}
|
||||
|
||||
@ -63,7 +67,7 @@ impl Application {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct ApplicationBaseUrl(pub String);
|
||||
|
||||
pub fn get_connection_pool(config: crate::configuration::DatabaseSettings) -> Pool<Postgres> {
|
||||
Pool::connect_lazy_with(config.with_db())
|
||||
|
||||
Reference in New Issue
Block a user