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

Merge pull request #4109 from kevinGodell/dev

httpStatic feature
This commit is contained in:
Nick O'Leary 2023-05-22 16:54:29 +01:00 committed by GitHub
commit 9479b56549
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -316,10 +316,10 @@ httpsPromise.then(function(startupHttps) {
} else {
continue;
}
sp.subRoot = formatRoot(sp.root);
sp.subRoot = formatRoot(sp.root || "/");
sp.root = formatRoot(path.posix.join(settings.httpStaticRoot,sp.subRoot));
}
settings.httpStatic = sanitised.length ? sanitised : false;
settings.httpStatic = sanitised.length ? sanitised : false;
}
// if we got a port from command line, use it (even if 0)
@ -427,6 +427,7 @@ httpsPromise.then(function(startupHttps) {
const sp = settings.httpStatic[si];
const filePath = sp.path;
const thisRoot = sp.root || "/";
const options = sp.options;
if(appUseMem[filePath + "::" + thisRoot]) {
continue;// this path and root already registered!
}
@ -434,7 +435,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, express.static(filePath, options));
}
}

View File

@ -223,10 +223,15 @@ module.exports = {
* to move httpAdminRoot
*/
//httpStatic: '/home/nol/node-red-static/', //single static source
/* OR multiple static sources can be created using an array of objects... */
/**
* OR multiple static sources can be created using an array of objects...
* Each object can also contain an options object for further configuration.
* See https://expressjs.com/en/api.html#express.static for available options.
*/
//httpStatic: [
// {path: '/home/nol/pics/', root: "/img/"},
// {path: '/home/nol/reports/', root: "/doc/"},
// {path: '/home/nol/videos/', root: "/vid/", options: {maxAge: '1d'}}
//],
/**
@ -431,7 +436,7 @@ module.exports = {
enabled: true
}
},
},
/*******************************************************************************