-
Notifications
You must be signed in to change notification settings - Fork 734
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
Support Functions in non-Pages environments #213
Conversation
🦋 Changeset detectedLatest commit: 618292c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you planning on exposing this for regular developers, or is this just for internal usage?
@@ -1,11 +1,13 @@ | |||
import path from "path"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it's a good time to make a build of this file too. I'd like to keep packages out of dependencies, and would rather deliver bundled files. In a followup PR is fine, but before GA.
Regular developers, yeah. There's a few other things I want to do before its ready for prime-time, but the hope is that some people chose to write Workers with this file-based routing. |
Co-authored-by: Sunil Pai <[email protected]>
23393cf
to
618292c
Compare
That package lock thing is a little worrisome, but maybe it's fine now. I'll test myself tomorrow. Feel free to land. |
Regenerated it properly in the latest commit. The changes now are just due to updated packages because we're not pinning versions. |
Adds support for building a Worker from a folder of functions which isn't tied to the Pages platform.
This lets developers use the same file-based routing system an simplified syntax when developing their own Workers!
For example, I can create a folder of functions:
And run
npx wrangler pages functions build --fallback-service='' --script-path=worker.js
.This will generate a Worker
worker.js
which will respond with "Hello, world!" for requests coming to/hello
.The
--fallback-service
determines the handling of requests which either don't match, or hit the end of theirnext
chain. In Pages world, we fallback toenv.ASSETS.fetch
which serves a project's static assets.In this case, when I pass
--fallback-service=''
, I'm signally that I don't want to fallback to any service, and instead, I fallback to the globalfetch
function. So if this Worker was deployed on my zone, when I make a request to anything other than/hello
, I'd hit my origin.If I wanted to fallback to another service or Durable Object, I could specify
--fallback-service MY_SERVICE
.Middleware, nested/routes, [segmented routes] are all supported with this.