-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve-prod-test.js
40 lines (32 loc) · 1.04 KB
/
serve-prod-test.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
/*******************************************************
* ⚠️ This server is for testing production builds in a
* development environment. It has not been checked for
* security. Please do not use in production!
*******************************************************/
const path = require('path');
const express = require('express');
const matchSupportedLocales = require('./match-supported-locales');
const port = 8080;
const rootDir = path.join(__dirname, 'dist/cooksm.art-client');
const locales = ['en', 'hu'];
const defaultLocale = 'en';
const server = express();
server.use(express.static(rootDir));
locales.forEach((locale) => {
server.get(`/${locale}/*`, (req, res) => {
res.sendFile(
path.resolve(rootDir, locale, 'index.html')
);
});
});
server.get('/', (req, res) => {
const closestSupportedLocale = matchSupportedLocales(
req.acceptsLanguages(),
locales,
defaultLocale
);
return res.redirect(`/${closestSupportedLocale}`);
});
server.listen(port, () =>
console.log(`App running at port ${port}…`)
);