-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
For single page apps with client-side routing the index.html
file needs to be served for any path that cannot be resolved otherwise, so that it can be handled by the client-side JS.
From the way it works in Express or Fastify I would expect this to work:
app.use(staticPlugin({ assets: './static', prefix: '/'}));
app.get('/*', () => Bun.file('./static/index.html'));
But with the Elysia static plugin it doesn't work. In this case I get the index.html
returned also for my static assets.
Would be nice if this could be addressed.
For now I cannot use the plugin and instead wrote this:
app.get('/*', async ({ path }) => {
const staticFile = Bun.file(`./static/${path}`);
const fallBackFile = Bun.file('./static/index.html');
return (await staticFile.exists()) ? staticFile : fallBackFile;
});
(I'm a little bit worried it might be vulnerable to path-traversal attacks, although from what I have tried it seems fine.)
michaelhthomas, aryzing, jl-pi, RokoTechnology, jdkaplan and 3 more
Metadata
Metadata
Assignees
Labels
No labels