-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
39 lines (28 loc) · 1.06 KB
/
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
const dotenv = require( "dotenv" );
const env = dotenv.config();
console.info( env.parsed );
const path = require( "path" );
const express = require( "express" );
const compression = require( "compression" );
// express init
const app = express();
// compression
app.use( compression() );
app.disable( "x-powered-by" );
// directory that we will serve
app.use( express.static( __dirname + "/dist/web-ui-template" ) );
// If not using Cloudflare Flexible SSL configuration redirect all requests to https
// https://support.cloudflare.com/hc/en-us/articles/115000219871-Troubleshooting-redirect-loop-errors-
// redirect all requests to index.html
app.get( "/*", function ( req, res ) {
let selectedLanguage = "en-US";
if ( req.acceptsLanguages( "fr" ) || req.url.startsWith( "/fr/" ) ) {
selectedLanguage = "fr";
}
res.sendFile( path.join( __dirname + "/dist/web-ui-template/" + selectedLanguage + "/index.html" ) );
} );
// listen port
const port = process.env.PORT || 4201;
app.listen( port, () => {
console.info( "UI Server is running on port: ", port );
} );