denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.53k stars 648 forks source link

feat: add `ctx.redirect()` helper #2358

Closed marvinhagemeister closed 7 months ago

marvinhagemeister commented 7 months ago

This PR adds a ctx.redirect(path, status) helper that aims to reduce the verbosity of having to manually create a Response obejct for a mere redirect.

// Before
new Response(null, {
  status: 307,
  headers: {
    Location: "/foo/bar"
  },
})

// After
ctx.redirect("/foo/bar", 307)

If the second parameter is not passed, it will default to 302.

deer commented 7 months ago

Hi @marvinhagemeister, cool feature, but what about docs? 🙃

I can open a PR if you'd like.