Skip to content

Commit 304dbff

Browse files
committed
Disable trailing slashes
1 parent 3ad123b commit 304dbff

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

server.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ function serve(folderName) {
99
import(`${configPath}/config.mjs`).then(({ default: config }) => {
1010
const app = express();
1111
app.use(morgan("tiny"));
12-
app.set("strict routing", true);
1312

13+
app.use((req, res, next) => {
14+
if (req.path.slice(-1) === "/" && req.path.length > 1) {
15+
const query = req.url.slice(req.path.length);
16+
const safePath = req.path.slice(0, -1).replace(/\/+/g, "/");
17+
res.redirect(301, safePath + query);
18+
} else {
19+
next();
20+
}
21+
});
1422

1523
const staticPath = path.join(fileURLToPath(configPath), folderName);
1624
app.use(

0 commit comments

Comments
 (0)