Skip to content

Commit

Permalink
GITHUB#19 Fix healthcheck with custom web root (BASE_URL) (bis)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanawel committed Jul 8, 2023
1 parent de15705 commit 15ac116
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]

Expand Down
5 changes: 2 additions & 3 deletions server/src/middleware/app/webroot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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) {
Expand Down

0 comments on commit 15ac116

Please sign in to comment.