Skip to content

Cloudflare hosting phase #1 - Express compat layer#568

Open
fredericbarthelet wants to merge 6 commits intomainfrom
fred/sky-258-switch-to-hono-as-router
Open

Cloudflare hosting phase #1 - Express compat layer#568
fredericbarthelet wants to merge 6 commits intomainfrom
fred/sky-258-switch-to-hono-as-router

Conversation

@fredericbarthelet
Copy link
Copy Markdown
Contributor

@fredericbarthelet fredericbarthelet commented Mar 16, 2026

Addresses #535

This is phase 1 of Cloudflare hosting support.

One big rework not initially planned was to get read of all readFileSync API calls that can't be used in a Cloudflare worker environment. We were relying on those to:

  • read handlebars template at runtime -> switch to a pre-compilation phase
  • read vite manifest for entrypoint location at runtime -> switch from json file read to js module export file

I created a separate issue to move away from native Node.js API in production build : #571

I also had to make 2 additional small changes compared to original plan:

  • remove the string literal from the dev only import statements to prevent esbuild from importing those (Vite deps like lightningcss are erroring wrangler build step)
  • remove the widgetsDevServer exports from the @skybridge/server barrel file (for the same reason). This is still here for retro-compatibility reason, but can be broken if need be

Run pnpm create skybridge@cloudflare and then npm run cloudflare:deploy in the generated directory to deploy on Cloudflare

Greptile Summary

This PR begins Cloudflare Workers hosting support (phase 1) by adding an Express compatibility layer. The McpServer.run() method now starts the HTTP server and then conditionally imports httpServerHandler from cloudflare:node to return a Workers-compatible fetch handler. In non-Workers environments, it returns undefined. Dynamic imports in express.ts are indirected through variables to prevent Cloudflare's bundler from statically resolving dev-only dependencies.

  • server.run() return type changed from Promise<void> to Promise<{ fetch: (...args: unknown[]) => unknown } | undefined> to expose the Cloudflare Workers fetch interface
  • Dev-only import() calls in express.ts use variable indirection to avoid bundler static analysis
  • Starter template now uses export default await server.run() for Workers module compatibility
  • widgetsDevServer removed from public exports in index.tsthis is a breaking change as documentation (docs/devtools/index.mdx) still references importing it from skybridge/server

Confidence Score: 4/5

  • This PR is generally safe to merge; the Cloudflare integration is well-implemented with a graceful fallback, but contains a breaking export removal that needs documentation alignment.
  • The Cloudflare Workers integration follows the documented pattern correctly and degrades gracefully in non-Workers environments. The dynamic import indirection is a proven bundler technique. Score is 4 instead of 5 due to the removal of the widgetsDevServer public export without updating the documentation that references it, which will break users following the "Custom Integration" guide.
  • packages/core/src/server/index.ts — removed widgetsDevServer export still referenced in documentation

Comments Outside Diff (1)

  1. packages/core/src/server/index.ts, line 10 (link)

    Breaking public export removal

    The widgetsDevServer export was removed here, but docs/devtools/index.mdx (line 81) still documents it as part of the "Custom Integration" guide:

    import { devtoolsStaticServer, widgetsDevServer } from "skybridge/server";

    Users following that documentation will get an import error after this change. The docs should be updated to remove or replace this reference — or the export should be kept if it's still intended for external use.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: packages/core/src/server/index.ts
Line: 10

Comment:
**Breaking public export removal**

The `widgetsDevServer` export was removed here, but `docs/devtools/index.mdx` (line 81) still documents it as part of the "Custom Integration" guide:

```typescript
import { devtoolsStaticServer, widgetsDevServer } from "skybridge/server";
```

Users following that documentation will get an import error after this change. The docs should be updated to remove or replace this reference — or the export should be kept if it's still intended for external use.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 25e58e2

@fredericbarthelet fredericbarthelet force-pushed the fred/sky-258-switch-to-hono-as-router branch 9 times, most recently from ab247c9 to 5ffcc02 Compare March 19, 2026 14:32
@fredericbarthelet fredericbarthelet force-pushed the fred/sky-258-switch-to-hono-as-router branch from 5ffcc02 to 203bd0a Compare March 19, 2026 14:47
@fredericbarthelet fredericbarthelet force-pushed the fred/sky-258-switch-to-hono-as-router branch from 203bd0a to ef94389 Compare March 19, 2026 14:48
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.

1 participant