elysia icon indicating copy to clipboard operation
elysia copied to clipboard

redirect routes

Open zoto-ff opened this issue 1 year ago • 2 comments

What is the problem this feature would solve?

write less code

What is the feature you are proposing to solve the problem?

const app = new Elysia()
    .redirect('/', '/docs')
    
    // or
    .redirect({
        '/': '/docs',
        '/old-docs': '/docs'
    })

will be nice with serve.static (oven-sh/bun#13540)

What alternatives have you considered?

.get('/', ({ redirect }) => redirect('/docs'))

zoto-ff avatar Aug 27 '24 22:08 zoto-ff

import { Elysia } from "elysia";

const app = new Elysia()
  .get("/", ({ set }) => (set.redirect = "/redirected"))
  .get("/redirected", () => "redirected")
  .listen(3000);

RaphaelNJ avatar Aug 30 '24 12:08 RaphaelNJ

@RaphaelNJ

we already have

app.get('/', ({ redirect }) => redirect('/docs'))

my idea is write less code and use new serve.static option, which makes such routes faster

ghost avatar Aug 30 '24 14:08 ghost

You can now inline redirect to Elysia handler, which will be added to serve.routes

import { redirect } from 'elysia'

const app = new Elysia()
	.get('/', redirect('/thing'))
	.get('/thing', 'thing')

Closing as complete

SaltyAom avatar Aug 04 '25 10:08 SaltyAom