{"action":"created","issue":{"url":"https://api.github.com/repos/expressjs/express/issues/3800","repository_url":"https://api.github.com/repos/expressjs/express","labels_url":"https://api.github.com/repos/expressjs/express/issues/3800/labels{/name}","comments_url":"https://api.github.com/repos/expressjs/express/issues/3800/comments","events_url":"https://api.github.com/repos/expressjs/express/issues/3800/events","html_url":"https://github.com/expressjs/express/issues/3800","id":380415005,"node_id":"MDU6SXNzdWUzODA0MTUwMDU=","number":3800,"title":"How to rewrite url when using routers","user":{"login":"barisusakli","id":2583394,"node_id":"MDQ6VXNlcjI1ODMzOTQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2583394?v=4","gravatar_id":"","url":"https://api.github.com/users/barisusakli","html_url":"https://github.com/barisusakli","followers_url":"https://api.github.com/users/barisusakli/followers","following_url":"https://api.github.com/users/barisusakli/following{/other_user}","gists_url":"https://api.github.com/users/barisusakli/gists{/gist_id}","starred_url":"https://api.github.com/users/barisusakli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barisusakli/subscriptions","organizations_url":"https://api.github.com/users/barisusakli/orgs","repos_url":"https://api.github.com/users/barisusakli/repos","events_url":"https://api.github.com/users/barisusakli/events{/privacy}","received_events_url":"https://api.github.com/users/barisusakli/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-11-13T20:43:24Z","updated_at":"2018-11-13T20:50:36Z","closed_at":null,"author_association":"NONE","body":"Hello, trying to rewrite the url to redirect requests but having some problems when the url doesn't have a trailing slash. Here is a minimal app to demonstrate.\r\n\r\n```\r\nconst express = require('express')\r\nconst app = express()\r\nconst port = 3000\r\nconst router = express.Router()\r\n\r\nconst subFolder = '/forum'\r\n\r\napp.use(subFolder, rewrite);\r\n\r\nfunction rewrite(req, res, next) {\r\n    console.log(req.path)\r\n    if (req.path !== '/') {\r\n        return next()\r\n    }\r\n    req.url = '/categories'\r\n    app.handle(req, res, next);\r\n}\r\n\r\nrouter.get('/regular-page', (req, res) => res.send('Hello World!'))\r\nrouter.get('/categories', (req, res) => res.send('Categories'));\r\napp.use(subFolder, router);\r\n\r\napp.listen(port, () => console.log(`Example app listening on port ${port}!`))\r\n```\r\n\r\nThe goal is to redirect `localhost:3000/forum` and `localhost:3000/forum/` to `localhost:3000:/forum/categories`. Right now only `localhost:3000:/forum/` works. The other just 404s.\r\n\r\nThanks.\r\n"},"comment":{"url":"https://api.github.com/repos/expressjs/express/issues/comments/438431757","html_url":"https://github.com/expressjs/express/issues/3800#issuecomment-438431757","issue_url":"https://api.github.com/repos/expressjs/express/issues/3800","id":438431757,"node_id":"MDEyOklzc3VlQ29tbWVudDQzODQzMTc1Nw==","user":{"login":"barisusakli","id":2583394,"node_id":"MDQ6VXNlcjI1ODMzOTQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2583394?v=4","gravatar_id":"","url":"https://api.github.com/users/barisusakli","html_url":"https://github.com/barisusakli","followers_url":"https://api.github.com/users/barisusakli/followers","following_url":"https://api.github.com/users/barisusakli/following{/other_user}","gists_url":"https://api.github.com/users/barisusakli/gists{/gist_id}","starred_url":"https://api.github.com/users/barisusakli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barisusakli/subscriptions","organizations_url":"https://api.github.com/users/barisusakli/orgs","repos_url":"https://api.github.com/users/barisusakli/repos","events_url":"https://api.github.com/users/barisusakli/events{/privacy}","received_events_url":"https://api.github.com/users/barisusakli/received_events","type":"User","site_admin":false},"created_at":"2018-11-13T20:50:36Z","updated_at":"2018-11-13T20:50:36Z","author_association":"NONE","body":"Hi @dougwilson `/forum/foo` should just go to `/forum/foo` only want to rewrite `/forum` and `/forum/` everything else should go to their regular handlers, so `/forum/regular-page` says `Hello World!`"}}
{"actor":{"display_login":"barisusakli"}}