workers-sdk
workers-sdk copied to clipboard
RFC: Add support for 'export default { fetch() }' in Pages Functions
This PR makes it possible to use a regular ol' export default { fetch() } within Pages Functions.
Any onRequest(Get|Head|Post|etc) take precedence, and if an onRequest is also included, the export default { fetch() } is not invoked.
I welcome feedback on the idea, and on the priority described above.
The only feature that's missing is passThroughOnException(), which we don't have in Pages Functions normally anyway.
To Do
- [ ] Log a warning on conflict between
export const onRequestandexport default { fetch() }
🦋 Changeset detected
Latest commit: c0a768e8bc28f8352b4f572a375e332da72838f6
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| wrangler | Patch |
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
A wrangler prerelease is available for testing. You can install this latest build in your project with:
npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2971109719/npm-package-wrangler-1740
You can reference the automatically updated head of this PR with:
npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/1740/npm-package-wrangler-1740
Or you can use npx with this latest build directly:
npx https://prerelease-registry.developers.workers.dev/runs/2971109719/npm-package-wrangler-1740 dev path/to/script.js
Codecov Report
Merging #1740 (c0a768e) into main (2b847a2) will decrease coverage by
0.04%. The diff coverage is50.00%.
@@ Coverage Diff @@
## main #1740 +/- ##
==========================================
- Coverage 80.24% 80.19% -0.05%
==========================================
Files 92 93 +1
Lines 6190 6226 +36
Branches 1597 1605 +8
==========================================
+ Hits 4967 4993 +26
- Misses 1223 1233 +10
| Impacted Files | Coverage Δ | |
|---|---|---|
| packages/wrangler/src/pages/functions/routes.ts | 8.33% <0.00%> (-0.37%) |
:arrow_down: |
| ...s/wrangler/src/pages/functions/filepath-routing.ts | 87.27% <47.05%> (-7.36%) |
:arrow_down: |
| ...ckages/wrangler/src/pages/functions/buildPlugin.ts | 15.00% <100.00%> (+2.17%) |
:arrow_up: |
| ...ckages/wrangler/src/pages/functions/buildWorker.ts | 13.72% <100.00%> (+1.72%) |
:arrow_up: |
| packages/wrangler/src/pages/functions/esbuild.ts | 100.00% <100.00%> (ø) |
|
| packages/wrangler/src/dev.tsx | 81.28% <0.00%> (+1.53%) |
:arrow_up: |
| ...ackages/wrangler/src/__tests__/helpers/mock-bin.ts | 100.00% <0.00%> (+5.26%) |
:arrow_up: |
How would this work with the new middleware stuff for Workers? https://github.com/cloudflare/wrangler2/pull/1735
Would that also be compatible here if/when it was exposed for user-facing stuff?
How would this work with the new middleware stuff for Workers? #1735
Would that also be compatible here if/when it was exposed for user-facing stuff?
The middleware works by being bundled in with wrangler (i.e. a non-bundled worker pushed up to the edge wouldn't register any of the middleware exported), so functions might have to implement it separately if they don't get bundled in the same way - would be nice to have the same interface and compatibility of middleware though
Closing this as we are encouraging people to create a _workers.js Worker in cases where Pages users want more control.