Here's my HTTP server built with Elysia and Bun:
import { Elysia } from 'elysia'
import { staticPlugin } from '@elysiajs/static'
import { html } from '@elysiajs/html'
// Instantiating the HTTP server
const server = new Elysia()
// Serving 'dist' folder to clients
server.use(staticPlugin('./dist'))
server.get('*', async () => {
return Bun.file('./dist/index.html')
})
server.listen(3000, () => {
console.log(`Website server is listening on port 3000`);
})
When I hit http://localhost:5002/
I get an error saying:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
I wonder if what I have to do in order to return an HTML file from a route with Elysia, so that the file will load it's script properly.
You can resolve it with below changes