diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 25 |
1 files changed, 21 insertions, 4 deletions
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; | |||
36 | use lazy_static::lazy_static; | 36 | use lazy_static::lazy_static; |
37 | use std::fs; | 37 | use std::fs; |
38 | use crate::config::Config; | 38 | use crate::config::Config; |
39 | use warp::{Filter}; | ||
40 | use log::{error}; | ||
39 | 41 | ||
40 | #[tokio::main] | 42 | #[tokio::main] |
41 | async fn main() { | 43 | async fn main() { |
42 | log4rs::init_file("log.conf.yml", log4rs::config::Deserializers::default()).unwrap(); | 44 | log4rs::init_file("log.conf.yml", log4rs::config::Deserializers::default()).unwrap(); |
43 | 45 | ||
44 | let config = match Config::read("config.yaml") { | 46 | let configs = vec!["config.yaml"]; |
45 | Some(c) => c, | 47 | |
48 | let combined_routes = configs.into_iter() | ||
49 | .filter_map(|filename| { | ||
50 | match Config::read(filename) { | ||
51 | Some(config) => Some(routes::network(Db::new(config))), | ||
52 | None => None, | ||
53 | } | ||
54 | }) | ||
55 | .reduce(|routes, route| routes.or(route).unify().boxed()); | ||
56 | |||
57 | let routes = match combined_routes { | ||
58 | Some(r) => r, | ||
46 | None => { | 59 | None => { |
47 | println!("Could not read config file, exiting."); | 60 | // Exit the program if there's no successfully loaded config file. |
61 | error!("Failed to load any config files!"); | ||
48 | return; | 62 | return; |
49 | }, | 63 | }, |
50 | }; | 64 | }; |
51 | 65 | ||
52 | let api = routes::application(Db::new(config)); | 66 | // gradecoin-site (zola) outputs a public/, we serve it here |
67 | let static_route = warp::any().and(warp::fs::dir("public")); | ||
68 | |||
69 | let api = routes.or(static_route); | ||
53 | 70 | ||
54 | // Start the server | 71 | // Start the server |
55 | let point = ([127, 0, 0, 1], 8080); | 72 | let point = ([127, 0, 0, 1], 8080); |