aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs25
-rw-r--r--src/routes.rs11
2 files changed, 25 insertions, 11 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;
36use lazy_static::lazy_static; 36use lazy_static::lazy_static;
37use std::fs; 37use std::fs;
38use crate::config::Config; 38use crate::config::Config;
39use warp::{Filter};
40use log::{error};
39 41
40#[tokio::main] 42#[tokio::main]
41async fn main() { 43async 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);
diff --git a/src/routes.rs b/src/routes.rs
index cdbfc08..f53a20c 100644
--- a/src/routes.rs
+++ b/src/routes.rs
@@ -3,20 +3,17 @@
3use crate::custom_filters; 3use crate::custom_filters;
4use crate::handlers; 4use crate::handlers;
5use crate::Db; 5use crate::Db;
6use warp::{Filter, Rejection, Reply}; 6use warp::{Filter, filters::BoxedFilter, Rejection, Reply};
7
8/// Every route combined
9pub fn application(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
10 // gradecoin-site (zola) outputs a public/, we serve it here
11 let static_route = warp::any().and(warp::fs::dir("public"));
12 7
8/// Every route combined for a single network
9pub fn network(db: Db) -> BoxedFilter<(impl Reply,)> {
13 transaction_list(db.clone()) 10 transaction_list(db.clone())
14 .or(register_user(db.clone())) 11 .or(register_user(db.clone()))
15 .or(auth_transaction_propose(db.clone())) 12 .or(auth_transaction_propose(db.clone()))
16 .or(auth_block_propose(db.clone())) 13 .or(auth_block_propose(db.clone()))
17 .or(list_users(db.clone())) 14 .or(list_users(db.clone()))
18 .or(block_list(db)) 15 .or(block_list(db))
19 .or(static_route) 16 .boxed()
20} 17}
21 18
22/// GET /user warp route 19/// GET /user warp route