Open dario-piotrowicz opened 1 month ago
[!NOTE] The main keypoints here are:
- prod works (build + run)
- dev works
- HMR in dev works
- single source-of-truth for the load context
The server build for CF doesn't really depend on the /functions
directory, since you control that file you could remove it, import the build/server/index.js
file from inside a _worker.js
file and use CF Pages in Advanced Mode.
The server build you import is just an object conforming to the Remix's ServerBuild interface that's the same regardless if you use CF, Node, Bun or Deno. The createPagesFunctionHandler
is the one handling the request to Remix and the response from Remix to CF, but you could also skip that function and go directly to createRequestHandler
from the @remix-run/cloudflare
package, this one is specific for the workerd runtime and not for CF Pages so it works also for CF Workers.
[!NOTE] the remix team has agreed on Remix to output to
build/client
andbuild/server
and then have the Cloudflare build logic do anything it wants and move those around intobuild/cloudflare-pages
(or whatever the name ends up being) with thebuildEnd
hook of theremix()
plugin
When producing deployment/production builds that target Cloudflare, such builds rely on the
/functions
directory, for example see:templates/cloudflare/functions/[[path]].ts
createPagesFunctionHandler
Instead of this, builds should use advanced mode and produce an
_worker.js
directory instead (basic example of the_worker.js
directory).This
Since the
[[path]].ts
file is part of the user facing API this would require user facing changes, as discussed a while back (internal discord thread) a solution could be to introduce acloudflare.ts
/_worker.ts
/etc... file that would be at the root of a Remix project and have such file renamed and moved in the appropriate_worker.js
directory in thebuildEnd
hook.Optionally a
getServerBuild
(or similar) utility (or even a path rewrite on the fly) could be introduced to hide from users the fact that relative import path to the Remix build pre file movement does not actually point to a real file