|
|
|
@ -341,9 +341,7 @@ module.exports.startWebServer = async (dtp) => {
|
|
|
|
|
module.app.use(async (req, res, next) => {
|
|
|
|
|
const { cache: cacheService } = dtp.services;
|
|
|
|
|
try {
|
|
|
|
|
res.locals.dtp = {
|
|
|
|
|
request: req,
|
|
|
|
|
};
|
|
|
|
|
res.locals.request = req;
|
|
|
|
|
|
|
|
|
|
const settingsKey = `settings:${dtp.config.site.domainKey}:site`;
|
|
|
|
|
res.locals.site = Object.assign({ }, dtp.config.site);
|
|
|
|
@ -359,6 +357,16 @@ module.exports.startWebServer = async (dtp) => {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Call out to application to register their custom middleware at the right
|
|
|
|
|
* point in the processing chain.
|
|
|
|
|
*/
|
|
|
|
|
module.log.debug('typeof dtp.config.registerMiddleware', { type: (typeof dtp.config.registerMiddleware) });
|
|
|
|
|
if (dtp.config && (typeof dtp.config.registerMiddleware === 'function')) {
|
|
|
|
|
module.log.info('registering custom application middleware');
|
|
|
|
|
await dtp.config.registerMiddleware(dtp, module.app);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* System Init
|
|
|
|
|
*/
|
|
|
|
@ -382,12 +390,7 @@ module.exports.startWebServer = async (dtp) => {
|
|
|
|
|
|
|
|
|
|
if (process.env.HTTP_ENABLE === 'enabled') {
|
|
|
|
|
if (process.env.HTTP_REDIRECT_SSL === 'enabled') {
|
|
|
|
|
module.log.info('creating HTTP SSL redirect app');
|
|
|
|
|
module.redirectApp = express();
|
|
|
|
|
module.redirectApp.use((req, res) => {
|
|
|
|
|
module.log.info('redirecting to SSL', { host: req.host, url: req.url });
|
|
|
|
|
res.redirect(`https://${process.env.DTP_SITE_DOMAIN}${req.url}`);
|
|
|
|
|
});
|
|
|
|
|
await module.createSslRedirectApp(dtp);
|
|
|
|
|
await module.createHttpServer(dtp, module.redirectApp);
|
|
|
|
|
} else {
|
|
|
|
|
await module.createHttpServer(dtp, module.app);
|
|
|
|
@ -434,6 +437,19 @@ module.createHttpsServer = async (dtp, app) => {
|
|
|
|
|
return module.https;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.createSslRedirectApp = async (/* dtp */) => {
|
|
|
|
|
module.log.info('creating HTTP SSL redirect app');
|
|
|
|
|
|
|
|
|
|
module.redirectApp = express();
|
|
|
|
|
|
|
|
|
|
module.redirectApp.use((req, res) => {
|
|
|
|
|
module.log.info('redirecting to SSL', { host: req.host, url: req.url });
|
|
|
|
|
res.redirect(`https://${process.env.DTP_SITE_DOMAIN}${req.url}`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return module.redirectApp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.startHttpServer = async (dtp, server, config) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
module.log.info('starting HTTP server', { port: config.port, bind: config.address });
|
|
|
|
|