From 33899763ef4a55cc051792ad20064a7ea6d6753c Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 21 Jun 2023 16:47:47 +0100 Subject: [PATCH] Add support for httpStatic middleware --- packages/node_modules/node-red/red.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index 5bb81e8bd..254a9b55b 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -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)); } }