diff --git a/Dockerfile b/Dockerfile index 95c8249..48c9dcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ WORKDIR /app EXPOSE 8080 HEALTHCHECK --interval=1m --timeout=20s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://localhost:${LISTEN_PORT:-8080}${BASE_URL:-/}healthcheck || exit 1 + CMD wget --no-verbose --tries=1 --spider http://localhost:${LISTEN_PORT:-8080}/${BASE_URL}/healthcheck || exit 1 CMD [ "node", "index.js" ] diff --git a/server/src/middleware/app/webroot.js b/server/src/middleware/app/webroot.js index dfccc0b..a8a0acb 100644 --- a/server/src/middleware/app/webroot.js +++ b/server/src/middleware/app/webroot.js @@ -10,10 +10,9 @@ console.info(`Using web root: ${trimedWebRoot}`); module.exports = function (app) { if (trimedWebRoot !== '') { - // Prevent access to any URL not starting with the configured BASE_URL app.use(function (req, res, next) { - if (!req.path.startsWith(`${trimedWebRoot}`)) { + if (!req.path.replace(new RegExp('^/+'), '/').startsWith(`${trimedWebRoot}`)) { console.error('[400]', 'Invalid incoming request URL:', `${req.method} ${req.path}`); res.status(400) .json({ @@ -28,7 +27,7 @@ module.exports = function (app) { }); // Load express-urlrewrite - app.use(rewrite(new RegExp(`^/?${trimedWebRoot}+(.*)`), '/$1')); + app.use(rewrite(new RegExp(`^/*${trimedWebRoot}+(.*)`), '/$1')); // Override response.redirect() to preprend BASE_URL app.use(function (req, res, next) {