1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #4229 from node-red/4125-httpstatic-middleware

Add support for httpStatic middleware
This commit is contained in:
Nick O'Leary 2023-06-21 16:57:00 +01:00 committed by GitHub
commit 2448e137c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -302,7 +302,7 @@ httpsPromise.then(function(startupHttps) {
settings.httpNodeAuth = settings.httpNodeAuth || settings.httpAuth;
}
if(settings.httpStatic) {
if (settings.httpStatic) {
settings.httpStaticRoot = formatRoot(settings.httpStaticRoot || "/");
const statics = Array.isArray(settings.httpStatic) ? settings.httpStatic : [settings.httpStatic];
const sanitised = [];
@ -414,13 +414,7 @@ httpsPromise.then(function(startupHttps) {
if (settings.httpNodeRoot !== false) {
app.use(settings.httpNodeRoot,RED.httpNode);
}
// if (settings.httpStatic) {
// settings.httpStaticAuth = settings.httpStaticAuth || settings.httpAuth;
// if (settings.httpStaticAuth) {
// app.use("/",basicAuthMiddleware(settings.httpStaticAuth.user,settings.httpStaticAuth.pass));
// }
// app.use("/",express.static(settings.httpStatic));
// }
if (settings.httpStatic) {
let appUseMem = {};
for (let si = 0; si < settings.httpStatic.length; si++) {
@ -428,6 +422,7 @@ httpsPromise.then(function(startupHttps) {
const filePath = sp.path;
const thisRoot = sp.root || "/";
const options = sp.options;
const middleware = sp.middleware;
if(appUseMem[filePath + "::" + thisRoot]) {
continue;// this path and root already registered!
}
@ -435,6 +430,9 @@ httpsPromise.then(function(startupHttps) {
if (settings.httpStaticAuth) {
app.use(thisRoot, basicAuthMiddleware(settings.httpStaticAuth.user, settings.httpStaticAuth.pass));
}
if (middleware) {
app.use(thisRoot, middleware)
}
app.use(thisRoot, express.static(filePath, options));
}
}