Skip to content

Commit ffc952c

Browse files
committed
implement internal redirects using basePath
1 parent 24ada9b commit ffc952c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/app.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ const rootRouter = Router()
4848
rootRouter.use("/", auth())
4949
rootRouter.use("/", wol())
5050

51+
app.use((req, res, next) => {
52+
const origRedirect = res.redirect.bind(res)
53+
res.redirect = function redirectOverride(...args) {
54+
let target = args.pop()
55+
56+
if (typeof target === "string" && target.startsWith("/")) {
57+
args.push(env.ENV.basePath + target)
58+
} else {
59+
args.push(target)
60+
}
61+
62+
return origRedirect(...args)
63+
}
64+
65+
next()
66+
})
67+
5168
app.use(env.ENV.basePath, rootRouter)
5269

5370
app.use((err, req, res, next) => {

0 commit comments

Comments
 (0)