middleware icon indicating copy to clipboard operation
middleware copied to clipboard

@hono/esbuild-transpiler responds content-type video/mp2t

Open Code-Hex opened this issue 2 years ago • 1 comments

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

Code-Hex avatar Nov 14 '23 06:11 Code-Hex

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.

yusukebe avatar Nov 14 '23 16:11 yusukebe