From f14c4bc7fc74d39b31b049c10421609e6e048a69 Mon Sep 17 00:00:00 2001 From: necrashter Date: Sat, 23 Apr 2022 15:09:43 +0300 Subject: Support for multiple configs/routes --- src/main.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 6edd67c..65b4430 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,20 +36,37 @@ use db::Db; use lazy_static::lazy_static; use std::fs; use crate::config::Config; +use warp::{Filter}; +use log::{error}; #[tokio::main] async fn main() { log4rs::init_file("log.conf.yml", log4rs::config::Deserializers::default()).unwrap(); - let config = match Config::read("config.yaml") { - Some(c) => c, + let configs = vec!["config.yaml"]; + + let combined_routes = configs.into_iter() + .filter_map(|filename| { + match Config::read(filename) { + Some(config) => Some(routes::network(Db::new(config))), + None => None, + } + }) + .reduce(|routes, route| routes.or(route).unify().boxed()); + + let routes = match combined_routes { + Some(r) => r, None => { - println!("Could not read config file, exiting."); + // Exit the program if there's no successfully loaded config file. + error!("Failed to load any config files!"); return; }, }; - let api = routes::application(Db::new(config)); + // gradecoin-site (zola) outputs a public/, we serve it here + let static_route = warp::any().and(warp::fs::dir("public")); + + let api = routes.or(static_route); // Start the server let point = ([127, 0, 0, 1], 8080); -- cgit v1.2.3-70-g09d2