feat: Make URL rewriting possible
enhancement
### What is the feature you are proposing?
I would like to see URL rewriting. This is useful for i18n.
Currently, it could be achieved like this:
```ts
app.use(async (c, next) => {
if (c.req.path !== '/rewrite') {
const url = new URL(c.req.url)
url.pathname = '/rewrite'
return await app.fetch(new Request(url.toString(), c.req.raw))
}
return next();
});
app.get('/', (c) => {
return c.text('Hello Hono!')
});
app.get('/rewrite', (c) => {
return c.text('Hello Hono! This is a rewritten path.')
});
```
However, I doubt if this is really performant. And won't it be more elegant to have a c.rewrite('...')?
2 条评论