Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefix '/' conflicts with get('*') #27

Open
Gn3po4g opened this issue Apr 30, 2024 · 1 comment
Open

prefix '/' conflicts with get('*') #27

Gn3po4g opened this issue Apr 30, 2024 · 1 comment

Comments

@Gn3po4g
Copy link

Gn3po4g commented Apr 30, 2024

new Elysia()
.use(staticPlugin({prefix: '/' }))
.get('*', "hello")
.listen(3000)

When build elysia as above, all requrest goes to get('*'). So could set get() as a fallback? That is, the request first goes to match static resources, and then matches the get route if static file is not found.

@Gn3po4g
Copy link
Author

Gn3po4g commented Apr 30, 2024

maybe like this

const loadStatic = (root: string) => async (app: Elysia) => {
  readdirSync(root, { recursive: true, withFileTypes: true })
    .filter(file => file.isFile())
    .forEach(file => app.get(file.name, Bun.file(`${root}/${file.name}`)))
  return app
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant