middleware
middleware copied to clipboard
@hono/esbuild-transpiler responds content-type video/mp2t
Hi 👋
I tried using @hono/esbuild-transpiler. I'm using Cloudflare Workers and confirmed it with wrangler dev. When returning a .ts file from the server, it comes back with a content-type of video/mp2t.
const app = new Hono()
app.get(
'/static/:scriptName{.+.tsx?}',
esbuildTranspiler({ wasmModule: wasm, contentType: 'text/javascript' }),
);
app.get('/static/*', serveStatic({ root: './' }));
$ curl http://localhost:8787/static/script.ts -i
HTTP/1.1 200 OK
Content-Length: 381
Content-Type: video/mp2t
import Alpine from "https://esm.sh/[email protected]";
window.Alpine = Alpine;
document.addEventListener("alpine:init", () => {
Alpine.directive(
"destroy",
(_el, { expression }, { evaluateLater, cleanup }) => {
const clean = evaluateLater(expression);
cleanup(() => clean());
}
);
Alpine.store("auth", {
currentUser: null
});
});
Alpine.start();
- @hono/esbuild-transpiler: 0.1.2
- hono: 3.9.2
- esbuild-wasm: 0.19.5
Hi @Code-Hex!
This issue arises because serve-static identifies .ts files as video/mp2t:
https://github.com/honojs/hono/blob/b1581430754d8ec6a340a781beaaefb985a4057a/src/utils/mime.ts#L71
I believe it's better to maintain this specification in serve-static. Alternatively, we can have the @hono/esbuild-transpiler set the correct content type for .ts files.