Skip to content
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

feat: add createApp without default routes #85

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

berlysia
Copy link
Contributor

If the user implementation includes import { createApp } from "honox/server", all routes are included in the bundle by the hardcoded import.meta.glob.

Even if the user gives the option of createApp to overwrite it, the hardcoded part is still there and will not be removed by DCE.

With this change, import { createApp } from "honox/server/base" can be used to bypass the hardcoded parts and control all bundled routes by the options we give.

This change also allows builds that only return dynamic routes from Cloudflare Workers, without unnecessary routes which is already SSGed.
(We still need to work, due to current @hono/vite-cloudflare-pages cannot serve SSGed files )

@berlysia berlysia changed the title feat: add createApp without default values feat: add createApp without default routes Feb 21, 2024
@yusukebe
Copy link
Member

Hi @berlysia

Does this PR mean we can write like the following?:

import { createApp } from 'honox/server/base'

const ROUTES = import.meta.glob('/src/routes/**/[a-z[-][a-z[_-]*.(tsx|ts)', {
  eager: true
})

// ...

const app = createApp({
  ROUTES,
  RENDERER,
  NOT_FOUND,
  ERROR,
  MIDDLEWARE,
  root: './src'
})

export default app

@berlysia
Copy link
Contributor Author

@yusukebe Yes! I'm sorry for the inconvenience

@yusukebe
Copy link
Member

@berlysia

I see! Looks good! And by separating the files, it's easier to see the code.

I'll merge now. Thanks!

@yusukebe yusukebe merged commit 660382c into honojs:main Feb 22, 2024
1 check passed
@berlysia berlysia deleted the server-without-defaults branch February 22, 2024 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants