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