-
Notifications
You must be signed in to change notification settings - Fork 123
/
index.js
44 lines (35 loc) · 1.13 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
42
43
44
const fs = require('fs');
const path = require('path');
const compression = require('compression');
const express = require('express');
const filemanagerMiddleware = require('@opuscapita/filemanager-server').middleware;
const logger = require('@opuscapita/filemanager-server').logger;
const env = require('./.env');
const config = {
fsRoot: path.resolve(__dirname, './demo-files'),
rootName: 'Customization area'
};
const app = express();
const host = process.env.HOST || 'localhost';
const port = process.env.PORT || '3020';
fs.writeFileSync(
path.resolve(__dirname, './static/env.js'),
'window.env = ' + JSON.stringify(env) + ';'
);
app.use(compression());
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
next();
});
const baseUrl = process.env.BASE_URL || '/';
app.use(baseUrl, filemanagerMiddleware(config));
app.use(baseUrl, express.static(path.resolve(__dirname, './static')));
app.listen(port, host, function(err) {
if (err) {
logger.error(err);
}
logger.info(`Server listening at https://${host}:${port}`);
});
process.on('exit', function() {
logger.warn('Server has been stopped');
});