honojs / honox

HonoX - Hono based meta framework
https://hono.dev
MIT License
1.64k stars 43 forks source link

[suggestion] createApp config in server.ts #66

Closed tosaken1116 closed 8 months ago

tosaken1116 commented 8 months ago

What is the feature you are proposing?

Thank you for developing a great framework! Currently, I am developing using Honox. I've set the routes directory to src/app/routes, and to accommodate this, I made the following changes in src/app/server.ts:

const app = createApp({
  root: "/src/app/routes",
  RENDERER: import.meta.glob("/src/app/routes/**/_renderer.tsx", {
    eager: true,
  }),
  ROUTES: import.meta.glob("/src/app/routes/**/[!_]*.(ts|tsx|mdx)", {
    eager: true,
  }),
});

Even though root is set, I found it inconvenient that changes to RENDERER and ROUTES are required for pages to reflect. Upon inspecting the source code, I noticed that all four strings ROUTES, RENDERER, NOT_FOUND, and ERROR contain /app/routes. Therefore, if root is set in the config, how about we automatically insert root into these parts unless there's specific config for ROUTES, RENDERER, NOT_FOUND, and ERROR?

For example, for NOT_FOUND_FILE:

 const NOT_FOUND_FILE =
    options?.NOT_FOUND ??
    import.meta.glob<NotFoundFile>(`${root}/**/_404.(ts|tsx)`, {
      eager: true,
    })
yusukebe commented 8 months ago

Hi @tosaken1116

Thanks for your comment.

Therefore, if root is set in the config, how about we automatically insert root into these parts unless there's specific config for ROUTES, RENDERER, NOT_FOUND, and ERROR?

Yeah, I also would like to make that! But, it can't by limitation of Vite:

You should also be aware that all the arguments in the import.meta.glob must be passed as literals. You can NOT use variables or expressions in them. https://vitejs.dev/guide/features#glob-import-caveats

So, unfortunately, we can't use variables in the path for import.meta.glob as you wrote 😒

tosaken1116 commented 8 months ago

Thank you for your reply! I apologize for making a suggestion without knowing the specifications of Vite.πŸ™

I'm looking forward to the future development of the framework!!

yusukebe commented 8 months ago

I apologize for making a suggestion without knowing the specifications of Vite.πŸ™

No problem!

I'm looking forward to the future development of the framework!!

Thanks!

I'll close this issue!