forked from RunOnFlux/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiServer.js
49 lines (43 loc) · 1.9 KB
/
apiServer.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
// Flux configuration
process.env.NODE_CONFIG_DIR = `${__dirname}/ZelBack/config/`;
const config = require('config');
// const fs = require('fs');
// const https = require('https');
// const path = require('path');
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 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 listening on port ${apiPort}!`);
serviceManager.startFluxFunctions();
});
}
initiate();