-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (48 loc) · 1.61 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const express_app = require("./backend/server.js");
//const contr_lang = require('./backend/controller/language.js');
const routes = require("./backend/controller/routes.js");
//Setup everything **********************************
setup_routes();
/** React to pre-configured routes (from routes.js) */
function setup_routes() {
let setup_route = function(key, methods) {
/*key is the address of the url -> e.g. /, or /about
* while value is an object which can consist of following
* parts:
*
* {
* "post":func, "get":func, "delete":func, "put":func
* }
*
* No method must be provided for an uri. */
let evaluate_route = function(method_name, method_func) {
console.log(
"app:evaluate_route: Setting up route -> " + key + " : " + method_name
);
switch (method_name.toLowerCase()) {
case "post":
express_app.post(key, method_func);
break;
case "get":
express_app.get(key, method_func);
break;
case "delete":
express_app.delete(key, method_func);
break;
case "put":
express_app.put(key, method_func);
break;
default:
console.error(
"app:setup_routes: HTTP-method not found -> " +
method_name.toLowerCase()
);
}
};
Object.entries(methods).forEach(([method_name, method_func]) =>
evaluate_route(method_name, method_func)
);
};
//for each object in routes (which consists multiple http methods)
Object.entries(routes).forEach(([key, methods]) => setup_route(key, methods));
}