From 4c46465e4608779426f9161a39a9b3ca2ce2e35b Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 4 Aug 2020 19:04:06 +0300 Subject: [PATCH] Add a hard 307 redirect. --- handshake-api/index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/handshake-api/index.js b/handshake-api/index.js index 6c00d2f4..d64f353c 100644 --- a/handshake-api/index.js +++ b/handshake-api/index.js @@ -68,6 +68,9 @@ server.use( proxy("nginx", { // eslint-disable-next-line no-unused-vars userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) { + if (!userReq.path.endsWith("/")) { + userRes.redirect(307, `${userReq.path}/`); + } if (headers.location && headers.location.match(startsWithSkylinkRegExp)) { headers.location = headers.location.replace(startsWithSkylinkRegExp, `/hns/${userReq.params.name}`); } @@ -96,6 +99,20 @@ server.use( }) ); +// server.get("/hns/:name", async (req, res) => { +// if (!req.path.endsWith('/')) { +// res.redirect(307, `${req.path}/`); +// } +// console.log(" > ", req.path) +// if (req.headers.location && req.headers.location.match(startsWithSkylinkRegExp)) { +// req.headers.location = req.headers.location.replace(startsWithSkylinkRegExp, `/hns/${userReq.params.name}`); +// console.log(" > to ", req.headers.location) +// } +// +// // res.redirect(307, '/to'); +// +// return req.headers; +// }); server.get("/hnsres/:name", resolveDomainHandler); server.listen(port, host, (error) => {