honojs / vite-plugins

Vite Plugins for Hono
https://hono.dev
130 stars 34 forks source link

[@hono/vite-cloudflare-pages] Support to serve static files on root directory #116

Closed ryuapp closed 6 months ago

ryuapp commented 7 months ago

Ref: https://github.com/honojs/starter/issues/31,

I want to use a public directory with file-based routing on HonoX. But @hono/vite-cloudflare-pages only supports favicon.ico in the root directory, other files must be placed under static directory. https://github.com/honojs/vite-plugins/blob/60d79860626d67622a38da138c0f12fcc33424ae/packages/cloudflare-pages/src/entry.ts#L39C1-L40C39

This makes it difficult to use robots.txt and sitemap.xml. It's possible to serve them manually, but it is troublesome to set them one by one.

It's better if a public directory can be freely routed. In addition, it would be even better if it was realized that like #110.

yusukebe commented 7 months ago

Hi @ryuapp

I think the better way is to create an option like staticPaths to apply serveStatic:

type CloudflarePagesOptions = {
  // ...
  staticPaths: string[]
}

const defaultOptions: Required<CloudflarePagesOptions> = {
  // ...
  staticPaths: ['/favicon.ico', '/static/*']
}

What do you think?

ryuapp commented 7 months ago

Hello @yusukebe

Thank you for your suggestion. The options looks good. It satisfies my requirements because that can freely route depending on the settings.

However, if I actually use HonoX, I create _routes.json with empty staticPaths. This is to avoid incurring charges with serveStatic. What I'm really looking for might be autogenerate _routes.json.

But now staticPaths is necessary in that it allows for free routing.

ryuapp commented 6 months ago

121 resolved this issue. Thank you.