-
In other route handlers like Express the last route will be executed if other routes didn't match. However in Elysia it is overriding the other routes: new Elysia()
.use(staticPlugin({
assets: 'public',
prefix: ''
}))
.get('/api', () => 'pong')
.get('/*', () => Bun.file('public/index.html'))
.listen(3000) What I expected this to do was:
What happened:
How can I achieve that with Elysia? |
Beta Was this translation helpful? Give feedback.
Answered by
crishoj
Jul 25, 2024
Replies: 1 comment
-
As far as I am aware, Elysia does not yet have an idiomatic way to specify a "default" or "catch-all" route. You could abuse the error handler a bit to achieve the same effect though: new Elysia()
.use(staticPlugin({
assets: 'public',
prefix: ''
}))
.get('/api', () => 'pong')
.onError(({code}) => {
if (code === 'NOT_FOUND') return Bun.file('public/index.html')
})
.listen(3000) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sekoyo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As far as I am aware, Elysia does not yet have an idiomatic way to specify a "default" or "catch-all" route.
You could abuse the error handler a bit to achieve the same effect though: