add httpStaticMiddleware before serve static files

This commit is contained in:
sak 2023-04-07 16:14:36 +07:00
parent 6179d1eef2
commit 8d06be81d8
2 changed files with 18 additions and 1 deletions

View File

@ -423,6 +423,11 @@ httpsPromise.then(function(startupHttps) {
// }
if (settings.httpStatic) {
let appUseMem = {};
let httpStaticMiddleware = (req, res, next) => next()
if (typeof settings.httpStaticMiddleware === 'function' || isArray(settings.httpStaticMiddleware)) {
httpStaticMiddleware = settings.httpStaticMiddleware
}
for (let si = 0; si < settings.httpStatic.length; si++) {
const sp = settings.httpStatic[si];
const filePath = sp.path;
@ -434,7 +439,7 @@ httpsPromise.then(function(startupHttps) {
if (settings.httpStaticAuth) {
app.use(thisRoot, basicAuthMiddleware(settings.httpStaticAuth.user, settings.httpStaticAuth.pass));
}
app.use(thisRoot, express.static(filePath));
app.use(thisRoot, httpStaticMiddleware, express.static(filePath));
}
}

View File

@ -239,6 +239,18 @@ module.exports = {
*/
//httpStaticRoot: '/static/',
/** The following property can be used to add a custom middleware function
* in front of all static files. This allows custom authentication to be
* applied to all http in nodes, or any other sort of common request processing.
* It can be a single function or an array of middleware functions.
*/
// httpStaticMiddleware: [
// require('compression')({ threshold: 0}),
// function(req,res,next) {
// // for example
// next();
// },
// ],
/*******************************************************************************
* Runtime Settings
* - lang