1
0
mirror of synced 2025-12-22 19:34:15 -05:00
Files
docs/middleware/trailing-slashes.js
Kevin Heis 688a274f1f Remove CSRF check (#29910)
* Use color_mode for gating "sign up" button

* Remove csrf check

* Add `res.removeHeader('set-cookie')` to cache-control

* Update static-assets.js

* Remove package

* Remove tough-cookie

* Update cache-control.js

* Update cache-control.js

* Update cache-control.js
2022-08-15 19:28:42 +00:00

24 lines
657 B
JavaScript

import { cacheControlFactory } from './cache-control.js'
const cacheControl = cacheControlFactory(60 * 60)
export default function trailingSlashes(req, res, next) {
if (req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS') {
const split = req.url.split('?')
let pathname = split.shift()
if (pathname !== '/' && pathname.endsWith('/')) {
while (pathname.endsWith('/')) {
pathname = pathname.slice(0, pathname.length - 1)
}
let url = pathname
if (split.length) {
url += `?${split.join('?')}`
}
cacheControl(res)
return res.redirect(301, url)
}
}
next()
}