-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (33 loc) · 1.01 KB
/
index.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
'use strict';
const path = require('path');
const fs = require('fs');
const express = require('express');
const nunjucks = require('nunjucks');
const request = require("request");
const urlencode = require('urlencode');
const basePath = process.env.BASE_PATH || '/';
const rootPath = path.resolve(__dirname, './dist');
const disableCache = process.env.DISABLE_CACHE || false;
const app = express();
if (disableCache) {
app.disable('view cache');
}
nunjucks.configure(rootPath, {
autoescape: true,
noCache: disableCache,
express: app
});
app.set('port', process.env.PORT || 8000);
app.get(basePath + '*', function(req, res) {
var filePath = path.resolve(rootPath, req.params[0]);
if (fs.existsSync(filePath)) {
var stats = fs.lstatSync(filePath);
if (stats.isFile()) {
return res.sendFile(filePath);
}
}
res.render('index.html', {authServerUrl: process.env.AUTH_SERVER_URL, base: basePath});
});
app.listen(app.get('port'), function() {
console.log('Listening port ' + app.get('port'));
});