Changeset 931b4cb in Klonkt


Ignore:
Timestamp:
06/28/2026 12:22:06 PM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
cca2e89
Parents:
0a58300
Message:

fix(proxy): tolerate leading double-slash paths (Apache [P] proxy)

A reverse proxy using 'RewriteRule (.*)$ http://localhost:3000/$1' sends for the root and
path for sub-paths (the captured $1 keeps its leading slash), which matched no Express route
→ the whole site 404'd behind such a proxy. Collapse leading duplicate slashes early so Klonkt
is resilient to that common Apache .htaccess setup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/server.js

    r0a58300 r931b4cb  
    149149if (!isDev) app.set('trust proxy', 1);
    150150
     151// Collapse leading duplicate slashes in the path. A reverse proxy that proxies with
     152// `RewriteRule ^(.*)$ http://localhost:3000/$1` (Apache [P]) sends "//" for the root and
     153// "//path" for sub-paths (the captured $1 keeps its leading slash) → Express matches no
     154// route → the whole site 404'd behind such a proxy. Normalising here makes Klonkt resilient
     155// to that common reverse-proxy setup. (Only the leading slashes; the query string is intact.)
     156app.use((req, res, next) => {
     157  if (req.url.startsWith('//')) req.url = req.url.replace(/^\/+/, '/');
     158  next();
     159});
     160
    151161// Create/migrate the schema BEFORE anything touches the DB: the session store
    152162// queries the `sessions` table on construction, so on a fresh install the tables
Note: See TracChangeset for help on using the changeset viewer.