forked from slsfi/digital-edition-frontend-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy-server.js
42 lines (32 loc) · 1.14 KB
/
proxy-server.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");
// * Define language codes of all languages the app is available in.
// * A translated server will be started for each of these.
// * The first language in the array is treated as default for the app.
const languages = ["sv", "en", "ar"];
const getTranslatedServer = (lang) => {
const distFolder = path.join(
process.cwd(),
`dist/app/server/${lang}`
);
const server = require(`${distFolder}/main.js`);
return server.app(lang);
};
function run() {
const port = process.env['PORT'] || 4201;
const translatedServers = {};
// Start up the Node server in each language.
languages.forEach(langCode => {
translatedServers[langCode] = getTranslatedServer(langCode);
});
const server = express();
for (const [langCode, langServer] of Object.entries(translatedServers)) {
server.use(`/${langCode}`, langServer);
}
// Use default language server if no language code defined in route.
server.use("", translatedServers[languages[0]]);
server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
run();