Add config to webserver data

This commit is contained in:
Raphaël Thériault 2019-10-08 12:06:30 -04:00
parent 9a0c5f2583
commit 4653c60f31
2 changed files with 5 additions and 2 deletions

View File

@ -52,13 +52,16 @@ fn main() {
let pool = setup::create_pool(&config.database_url, config.pool_size);
let port = config.port;
HttpServer::new(move || {
App::new()
.data(config.clone())
.data(pool.clone())
.wrap(middleware::Logger::default())
.route("/", web::get().to(index))
})
.bind(&format!("localhost:{}", config.port))
.bind(&format!("localhost:{}", port))
.unwrap_or_else(|e| {
eprintln!("Can't bind webserver to specified port: {}.", e);
process::exit(1);

View File

@ -28,7 +28,7 @@ fn get_config_path() -> PathBuf {
}
/// Application configuration
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
#[serde(default)]
pub struct Config {
/// Port to listen on