mirror of
https://github.com/Permissionless-Software-Foundation/psf-bch-api.git
synced 2026-09-21 16:52:00 -07:00
Merge pull request #15 from Permissionless-Software-Foundation/ct-unstable
fix(forward slashes): Fixing express specific issue
This commit is contained in:
+6
-6
@@ -76,13 +76,13 @@ class Server {
|
|||||||
|
|
||||||
// URL normalization middleware - collapse multiple slashes
|
// URL normalization middleware - collapse multiple slashes
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
if (req.path && req.path.includes('//')) {
|
if (req.url && req.url.includes('//')) {
|
||||||
|
// Split URL into path and query string
|
||||||
|
const [path, queryString] = req.url.split('?')
|
||||||
// Collapse multiple consecutive slashes into a single slash
|
// Collapse multiple consecutive slashes into a single slash
|
||||||
const normalizedPath = req.path.replace(/\/+/g, '/')
|
const normalizedPath = path.replace(/\/+/g, '/')
|
||||||
// Reconstruct req.url with normalized path
|
// Reconstruct req.url with normalized path (req.path is read-only and will auto-update)
|
||||||
const queryString = req.url.includes('?') ? req.url.substring(req.url.indexOf('?')) : ''
|
req.url = queryString ? `${normalizedPath}?${queryString}` : normalizedPath
|
||||||
req.url = normalizedPath + queryString
|
|
||||||
req.path = normalizedPath
|
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user