forked from RunOnFlux/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
73 lines (61 loc) · 2.49 KB
/
app.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
process.env.NODE_CONFIG_DIR = `${__dirname}/ZelBack/config/`;
// Flux configuration
const config = require('config');
const compression = require('compression');
// const fs = require('fs');
// const https = require('https');
const path = require('path');
const express = require('express');
const app = require('./ZelBack/src/lib/server');
const log = require('./ZelBack/src/lib/log');
const serviceManager = require('./ZelBack/src/services/serviceManager');
const upnpService = require('./ZelBack/src/services/upnpService');
const userconfig = require('./config/userconfig');
const apiPort = userconfig.initial.apiport || config.server.apiport;
const homePort = +apiPort - 1;
// const key = fs.readFileSync(path.join(__dirname, './certs/selfsigned.key'), 'utf8');
// const cert = fs.readFileSync(path.join(__dirname, './certs/selfsigned.crt'), 'utf8');
// const credentials = { key, cert };
// const httpsServer = https.createServer(credentials, app);
// const apiporthttps = +apiPort + 1;
// httpsServer.listen(config.server.apiporthttps, () => {
// log.info(`Flux https listening on port ${config.server.apiporthttps}!`);
// });
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();
}
}
app.listen(apiPort, () => {
log.info(`Flux running on port ${apiPort}!`);
serviceManager.startFluxFunctions();
});
// Flux Home configuration
const home = path.join(__dirname, './HomeUI/dist');
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'));
});
homeApp.listen(homePort, () => {
log.info(`Flux Home running on port ${homePort}!`);
});
}
initiate();