static file not able to serve #3226
Unanswered
arjunajsts
asked this question in
Q&A
Replies: 1 comment
-
Not sure if that helps, but you may need to rewrite the url to get the correct path: app.use(
"/tiles/*",
serveStatic({
root: "./tiles/",
// https://github.com/honojs/node-server/issues/118#issuecomment-1873352464
rewriteRequestPath: (path: string) => path.replace(/^\/tiles/, ""),
onNotFound: (path, c) => {
console.log(`${path} is not found, request to ${c.req.path}`);
},
})
); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
import { Hono } from "hono";
import { serve } from "@hono/node-server";
import { serveStatic } from '@hono/node-server/serve-static';
const app = new Hono();
app.use('/static/*', async(c, next) => {
console.log(
Request for static file: ${c.req.url}
);await serveStatic({ root: './files' })(c, next);
return next()
});
app.get('/', (c) => {
console.log("Root route accessed");
return c.json({ "message": "Hello, world!" });
});
serve({
fetch: app.fetch,
port: 8787,
});
console.log("Server is running on http://localhost:8787");
Beta Was this translation helpful? Give feedback.
All reactions