-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
_worker.js/
directory support in Pages
- Loading branch information
1 parent
0a77990
commit 4f632cb
Showing
19 changed files
with
413 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
feat: Add support for the undocumented `_worker.js/` directory in Pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "pages-workerjs-directory", | ||
"version": "0.0.0", | ||
"private": true, | ||
"sideEffects": false, | ||
"scripts": { | ||
"check:type": "tsc", | ||
"dev": "npx wrangler pages dev public --port 8794", | ||
"test": "npx vitest", | ||
"test:ci": "npx vitest" | ||
}, | ||
"devDependencies": { | ||
"undici": "^5.9.1" | ||
}, | ||
"engines": { | ||
"node": ">=16.13" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
fixtures/pages-workerjs-directory/public/_worker.js/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
async fetch(request, env) { | ||
const { pathname } = new URL(request.url); | ||
if (pathname !== "/") { | ||
return new Response((await import(`./${pathname.slice(1)}`)).default); | ||
} | ||
|
||
return env.ASSETS.fetch(request); | ||
}, | ||
}; |
1 change: 1 addition & 0 deletions
1
fixtures/pages-workerjs-directory/public/_worker.js/other-script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "test"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello, world!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { resolve } from "node:path"; | ||
import { fetch } from "undici"; | ||
import { describe, it } from "vitest"; | ||
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived"; | ||
|
||
describe.concurrent("Pages _worker.js/ directory", () => { | ||
it("should support non-bundling with 'dev'", async ({ expect }) => { | ||
const { ip, port, stop } = await runWranglerPagesDev( | ||
resolve(__dirname, ".."), | ||
"public", | ||
["--port=0"] | ||
); | ||
await expect( | ||
fetch(`http://${ip}:${port}/`).then((resp) => resp.text()) | ||
).resolves.toContain("Hello, world!"); | ||
await expect( | ||
fetch(`http://${ip}:${port}/other-script`).then((resp) => resp.text()) | ||
).resolves.toContain("test"); | ||
await stop(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"esModuleInterop": true, | ||
"module": "CommonJS", | ||
"lib": ["ES2020"], | ||
"types": ["node"], | ||
"moduleResolution": "node", | ||
"noEmit": true | ||
}, | ||
"include": ["tests", "../../node-types.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.