fix custom public folders for dns domains (#6018)
Signed-off-by: si458 <simonsmith5521@gmail.com>
Simon Smith committed
Apr 12, 2024 at 10:43 UTC
f5891f294690a22b42b1449201406122ad369c68
1 file changed
+11
-8
webserver.js
+11
-8
@@ -7074,14 +7074,16 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
7074
}
7075
7076
// Indicates to ExpressJS that the override public folder should be used to serve static files.
7077
- if (parent.config.domains[i].webpublicpath != null) {
7078
- // Use domain public path
7079
- obj.app.use(url, obj.express.static(parent.config.domains[i].webpublicpath));
7080
- } else if (obj.parent.webPublicOverridePath != null) {
7081
- // Use override path
7082
- obj.app.use(url, obj.express.static(obj.parent.webPublicOverridePath));
7083
- }
7084
-
7077
+ obj.app.use(url, function(req, res, next){
7078
+ var domain = getDomain(req);
7079
+ if (domain.webpublicpath != null) { // Use domain public path
7080
+ obj.express.static(domain.webpublicpath)(req, res, next);
7081
+ } else if (obj.parent.webPublicOverridePath != null) { // Use override path
7082
+ obj.express.static(obj.parent.webPublicOverridePath)(req, res, next);
7083
+ } else { // carry on and use default public path
7084
+ next();
7085
+ }
7086
+ });
7087
// Indicates to ExpressJS that the default public folder should be used to serve static files.
7088
obj.app.use(url, obj.express.static(obj.parent.webPublicPath));
7089
@@ -7122,6 +7124,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
7124
var domain = getDomain(req);
7125
if ((domain == null) || (domain.auth == 'sspi')) { res.sendStatus(404); return; }
7126
if ((domain.loginkey != null) && (domain.loginkey.indexOf(req.query.key) == -1)) { res.sendStatus(404); return; } // Check 3FA URL
7127
+ if (obj.args.nice404 == false) { res.sendStatus(404); return; }
7128
const cspNonce = obj.crypto.randomBytes(15).toString('base64');
7129
res.set({ 'Content-Security-Policy': "default-src 'none'; script-src 'self' 'nonce-" + cspNonce + "'; img-src 'self'; style-src 'self' 'nonce-" + cspNonce + "';" }); // This page supports very tight CSP policy
7130
res.status(404).render(getRenderPage((domain.sitestyle == 2) ? 'error4042' : 'error404', req, domain), getRenderArgs({ cspNonce: cspNonce }, req, domain));