forked from RunOnFlux/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
homeServer.js
52 lines (44 loc) · 1.69 KB
/
homeServer.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
45
46
47
48
49
50
51
52
process.env.NODE_CONFIG_DIR = `${__dirname}/ZelBack/config/`;
// Flux Home configuration
const config = require('config');
const compression = require('compression');
const path = require('path');
const express = require('express');
const log = require('./ZelBack/src/lib/log');
const upnpService = require('./ZelBack/src/services/upnpService');
const home = path.join(__dirname, './HomeUI/dist');
const userconfig = require('./config/userconfig');
const homeApp = express();
homeApp.use(compression());
homeApp.use(express.static(home));
homeApp.get('/robots.txt', (req, res) => {
res.type('text/plain');
res.send('User-agent: *\nDisallow: /');
});
homeApp.get('*', (req, res) => {
res.sendFile(path.join(home, 'index.html'));
});
const apiPort = userconfig.initial.apiport || config.server.apiport;
const homePort = apiPort - 1;
async function initiate() {
if (!config.server.allowedPorts.includes(+apiPort)) {
log.error(`Flux port ${apiPort} is not supported. Shutting down.`);
process.exit();
}
if (userconfig.initial.apiport && userconfig.initial.apiport !== config.server.apiport) {
const verifyUpnp = await upnpService.verifyUPNPsupport(apiPort);
if (verifyUpnp !== true) {
log.error(`Flux port ${userconfig.initial.apiport} specified but UPnP failed to verify support. Shutting down.`);
process.exit();
}
const setupUpnp = await upnpService.setupUPNP(apiPort);
if (setupUpnp !== true) {
log.error(`Flux port ${userconfig.initial.apiport} specified but UPnP failed to map to api or home port. Shutting down.`);
process.exit();
}
}
homeApp.listen(homePort, () => {
console.log(`Flux Home running on port ${homePort}!`);
});
}
initiate();