|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const glob = require('glob');
|
|
|
|
|
|
|
|
|
|
const express = require('express');
|
|
|
|
@ -300,8 +301,8 @@ module.exports.startWebServer = async (dtp) => {
|
|
|
|
|
domain: process.env.DTP_SITE_DOMAIN,
|
|
|
|
|
path: '/',
|
|
|
|
|
httpOnly: true,
|
|
|
|
|
secure: false,
|
|
|
|
|
sameSite: 'strict',
|
|
|
|
|
secure: process.env.HTTP_COOKIE_SECURE === 'enabled',
|
|
|
|
|
sameSite: process.env.HTTP_COOKIE_SAMESITE || false,
|
|
|
|
|
expires: SESSION_DURATION,
|
|
|
|
|
},
|
|
|
|
|
store: null,
|
|
|
|
@ -309,7 +310,6 @@ module.exports.startWebServer = async (dtp) => {
|
|
|
|
|
module.sessionConfig.store = sessionStore;
|
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
|
module.app.set('trust proxy', 1);
|
|
|
|
|
// module.sessionConfig.cookie.secure = true;
|
|
|
|
|
}
|
|
|
|
|
module.app.use(session(module.sessionConfig));
|
|
|
|
|
|
|
|
|
@ -369,21 +369,78 @@ module.exports.startWebServer = async (dtp) => {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (process.env.HTTP_ENABLE === 'enabled') {
|
|
|
|
|
await module.createHttpServer(dtp);
|
|
|
|
|
}
|
|
|
|
|
if (process.env.HTTPS_ENABLE === 'enabled') {
|
|
|
|
|
await module.createHttpsServer(dtp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// prefer to attach Socket.io to the HTTPS server and fall back to HTTP
|
|
|
|
|
await module.createSocketServer(dtp, module.https || module.http);
|
|
|
|
|
|
|
|
|
|
if (module.http) {
|
|
|
|
|
module.log.info('starting HTTP server', {
|
|
|
|
|
port: dtp.config.http.port,
|
|
|
|
|
bind: dtp.config.http.address,
|
|
|
|
|
});
|
|
|
|
|
await module.startHttpServer(dtp, module.http, dtp.config.http);
|
|
|
|
|
}
|
|
|
|
|
if (module.https) {
|
|
|
|
|
module.log.info('starting HTTPS server', {
|
|
|
|
|
port: dtp.config.https.port,
|
|
|
|
|
bind: dtp.config.https.address,
|
|
|
|
|
});
|
|
|
|
|
await module.startHttpServer(dtp, module.https, dtp.config.https);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.log.info(`${dtp.config.component.name} platform online`, {
|
|
|
|
|
http: dtp.config.http.port,
|
|
|
|
|
https: dtp.config.https.port,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.createHttpServer = async (/* dtp */) => {
|
|
|
|
|
module.log.info('creating HTTP server');
|
|
|
|
|
module.http = require('http').createServer(module.app);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.createHttpsServer = async (dtp) => {
|
|
|
|
|
const httpsOptions = {
|
|
|
|
|
cert: await fs.promises.readFile(
|
|
|
|
|
process.env.HTTPS_SSL_CRT || path.join(dtp.config.root, 'ssl', 'dtp-webapp.crt')
|
|
|
|
|
),
|
|
|
|
|
key: await fs.promises.readFile(
|
|
|
|
|
process.env.HTTPS_SSL_KEY || path.join(dtp.config.root, 'ssl', 'dtp-webapp.key')
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.log.info('creating HTTPS server');
|
|
|
|
|
module.https = require('https').createServer(httpsOptions, module.app);
|
|
|
|
|
|
|
|
|
|
return module.https;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.startHttpServer = async (dtp, server, config) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
module.log.info('starting HTTP server', { port: config.port, bind: config.address });
|
|
|
|
|
server.listen(config.port, config.address, (err) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return reject(err);
|
|
|
|
|
}
|
|
|
|
|
return resolve();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.createSocketServer = async (dtp, http) => {
|
|
|
|
|
module.log.info('creating Socket.io server');
|
|
|
|
|
const { SiteIoServer } = require(path.join(__dirname, 'site-ioserver'));
|
|
|
|
|
|
|
|
|
|
module.io = new SiteIoServer(dtp);
|
|
|
|
|
await module.io.start(module.http);
|
|
|
|
|
await module.io.start(http);
|
|
|
|
|
|
|
|
|
|
module.log.info('starting HTTP server', {
|
|
|
|
|
port: dtp.config.http.port,
|
|
|
|
|
bind: dtp.config.http.address,
|
|
|
|
|
});
|
|
|
|
|
module.http.listen(dtp.config.http.port, dtp.config.http.address, ( ) => {
|
|
|
|
|
module.log.info(`${dtp.config.component.name} platform online`, { port: dtp.config.http.port });
|
|
|
|
|
});
|
|
|
|
|
return module.io;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports.shutdown = async ( ) => {
|
|
|
|
|