-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·42 lines (29 loc) · 1.22 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
const express = require("express");
const path = require("path");
const env = require("ova_env");
require("./errors");
const app = express();
// { Cookie parser }
app.use(require("cookie-parser")());
// { Favicon }
app.use("/favicon.ico", express.static(path.join(".", "assets", "media", "favicon.ico")));
// { Assets }
app.use("/assets", express.static("."+path.sep+"assets"));
// { Translatable endpoints }
for(let lang of ["", ... env.supported_languages]) {
let lang_path = (lang ? "/":"")+lang;
// { Language middleware }
app.use(lang_path, (_req, _res, _next) => {
_req.lang = lang ? lang:process.env.DEFAULT_LANGUAGE;
let url = new URL(_req.originalUrl, "http://"+_req.headers.host);
_req.realOriginalUrl = lang ? url.pathname.substr(3):url.pathname;
_next();
});
app.use(lang_path+"/email-confirmation/:token", require("./controllers/email_confirmation"));
app.use(lang_path+"/register", require("./controllers/sign_up"));
app.use(lang_path+"/login", require("./controllers/login"));
// { User dashboard }
app.use(lang_path+"/dashboard", require("./controllers/dashboard"));
}
app.use("/", (_req, _res) => _res.redirect(302, "/fr/login"));
module.exports = app;