Can hono serve static site? #4390
-
|
I am trying to use Hono as my API backend. My frontend is just a set of index.html and few JS and CSS files. Is it possible that This way I will not use 2 different servers or containers for my app but one URL that serves both. Because my app is tiny container that is launched for every project customer creates, there might be 1 000 of those and I do not want to multiply it to 2 services running for one project. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You can use Something like this: // Serve static files like images, css, js from the ./public folder when accessing /web
app.use('/web/*', serveStatic({ root: './public' }))
// If no specific file is found under /web, serve the default index.html
app.get('/web/*', serveStatic({ path: './public/index.html' }))
// For API routes
app.get('/api/test', (c) => {
return c.json({ message: 'Healthy!' })
})You can read more about it here: https://hono.dev/docs/getting-started/nodejs#serve-static-files |
Beta Was this translation helpful? Give feedback.
You can use
serveStaticfrom Hono to achieve that.Something like this:
You can read more about it here: https://hono.dev/docs/getting-started/nodejs#serve-static-files