-
-
Notifications
You must be signed in to change notification settings - Fork 619
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
Hono not picking up MIME types correctly (I think) #3736
Comments
Hi, I'm currently working on this issue. |
Awesome, thanks! :) |
@sushichan044 Thanks! Please do it. |
Hello, For now I've done that but if you reload the page on a different route it doesn't work import { serveStatic } from "hono/serve-static";
app.use(
"*",
serveStatic({
root: "./dist",
getContent: async (path, c) => {
try {
const data = await fs.readFile(path);
let contentType = "text/plain";
if (path.endsWith(".html")) {
contentType = "text/html";
} else if (path.endsWith(".js")) {
contentType = "application/javascript";
} else if (path.endsWith(".css")) {
contentType = "text/css";
} else if (path.endsWith(".json")) {
contentType = "application/json";
} else if (path.endsWith(".png")) {
contentType = "image/png";
} else if (path.endsWith(".jpg") || path.endsWith(".jpeg")) {
contentType = "image/jpeg";
}
return new Response(data, {
headers: {
"Content-Type": contentType,
},
});
} catch (error) {
return null;
}
},
})
); |
This happens with different combinations of middleware that modify the |
What version of Hono are you using?
4.6.12
What runtime/platform is your app running on? (with version if possible)
Node 22 LTS
What steps can reproduce the bug?
index.html
)Content-Type
oftext/plain; charset=utf-8
, nottext/html
.What is the expected behavior?
When I try to make a request to the server on any path (per my example code), I should get the content returned as
text/html
, nottext/plain
.What do you see instead?
The content comes through as
text/plain
, which prevents it from rendering in the browser correctly.Additional information
The code I'm running is being executed in a
nodejs:22-slim
Docker image on Fly.io.The text was updated successfully, but these errors were encountered: