|
@ -341,9 +341,7 @@ module.exports.startWebServer = async (dtp) => { |
|
|
module.app.use(async (req, res, next) => { |
|
|
module.app.use(async (req, res, next) => { |
|
|
const { cache: cacheService } = dtp.services; |
|
|
const { cache: cacheService } = dtp.services; |
|
|
try { |
|
|
try { |
|
|
res.locals.dtp = { |
|
|
res.locals.request = req; |
|
|
request: req, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const settingsKey = `settings:${dtp.config.site.domainKey}:site`; |
|
|
const settingsKey = `settings:${dtp.config.site.domainKey}:site`; |
|
|
res.locals.site = Object.assign({ }, dtp.config.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 |
|
|
* System Init |
|
|
*/ |
|
|
*/ |
|
@ -382,12 +390,7 @@ module.exports.startWebServer = async (dtp) => { |
|
|
|
|
|
|
|
|
if (process.env.HTTP_ENABLE === 'enabled') { |
|
|
if (process.env.HTTP_ENABLE === 'enabled') { |
|
|
if (process.env.HTTP_REDIRECT_SSL === 'enabled') { |
|
|
if (process.env.HTTP_REDIRECT_SSL === 'enabled') { |
|
|
module.log.info('creating HTTP SSL redirect app'); |
|
|
await module.createSslRedirectApp(dtp); |
|
|
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.createHttpServer(dtp, module.redirectApp); |
|
|
await module.createHttpServer(dtp, module.redirectApp); |
|
|
} else { |
|
|
} else { |
|
|
await module.createHttpServer(dtp, module.app); |
|
|
await module.createHttpServer(dtp, module.app); |
|
@ -434,6 +437,19 @@ module.createHttpsServer = async (dtp, app) => { |
|
|
return module.https; |
|
|
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) => { |
|
|
module.startHttpServer = async (dtp, server, config) => { |
|
|
return new Promise((resolve, reject) => { |
|
|
return new Promise((resolve, reject) => { |
|
|
module.log.info('starting HTTP server', { port: config.port, bind: config.address }); |
|
|
module.log.info('starting HTTP server', { port: config.port, bind: config.address }); |
|
|