-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into vitest-fixtures
- Loading branch information
Showing
16 changed files
with
200 additions
and
7 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,7 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: Pages Plugin routing when mounted at the root of a project | ||
|
||
Previously, there was a bug which meant that Plugins mounted at the root of a Pages project were not correctly matching incoming requests. This change fixes that bug so Plugins mounted at the root should now correctly work. |
3 changes: 3 additions & 0 deletions
3
fixtures/pages-functions-app/functions/mounted-with-param/[p]/plugin/_middleware.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import examplePlugin from "../../../../../pages-plugin-example"; | ||
|
||
export const onRequest = examplePlugin({ footerText: "Set from a Plugin!" }); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const onRequest = () => new Response("Response from a nested folder"); |
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,3 @@ | ||
export const onRequest = () => { | ||
return new Response("This should return a 502 status code", { status: 502 }); | ||
}; |
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 @@ | ||
cdn-cgi/ |
3 changes: 3 additions & 0 deletions
3
fixtures/pages-plugin-mounted-on-root-app/functions/_middleware.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import examplePlugin from "../../pages-plugin-example"; | ||
|
||
export const onRequest = examplePlugin({ footerText: "Set from a Plugin!" }); |
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,4 @@ | ||
declare module "*.html" { | ||
const content: string; | ||
export default content; | ||
} |
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,36 @@ | ||
{ | ||
"name": "pages-plugin-mounted-on-root-app", | ||
"version": "0.0.0", | ||
"private": true, | ||
"sideEffects": false, | ||
"main": "dist/worker.js", | ||
"scripts": { | ||
"check:type": "tsc && tsc -p tests/tsconfig.json", | ||
"dev": "npx wrangler pages dev public --port 8793", | ||
"test": "npx jest --forceExit", | ||
"test:ci": "npx jest --forceExit" | ||
}, | ||
"jest": { | ||
"restoreMocks": true, | ||
"testRegex": ".*.(test|spec)\\.[jt]sx?$", | ||
"testTimeout": 30000, | ||
"transform": { | ||
"^.+\\.c?(t|j)sx?$": [ | ||
"esbuild-jest", | ||
{ | ||
"sourcemap": true | ||
} | ||
] | ||
}, | ||
"transformIgnorePatterns": [ | ||
"node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20221111.1", | ||
"undici": "^5.9.1" | ||
}, | ||
"engines": { | ||
"node": ">=16.13" | ||
} | ||
} |
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,6 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<h1>Hello, world!</h1> | ||
</body> | ||
</html> |
51 changes: 51 additions & 0 deletions
51
fixtures/pages-plugin-mounted-on-root-app/tests/index.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { fork } from "child_process"; | ||
import * as path from "path"; | ||
import { fetch } from "undici"; | ||
import type { ChildProcess } from "child_process"; | ||
|
||
describe("Pages Functions", () => { | ||
let wranglerProcess: ChildProcess; | ||
let ip: string; | ||
let port: number; | ||
let resolveReadyPromise: (value: unknown) => void; | ||
const readyPromise = new Promise((resolve) => { | ||
resolveReadyPromise = resolve; | ||
}); | ||
|
||
beforeAll(async () => { | ||
wranglerProcess = fork( | ||
path.join("..", "..", "packages", "wrangler", "bin", "wrangler.js"), | ||
["pages", "dev", "public", "--port=0"], | ||
{ | ||
stdio: ["inherit", "inherit", "inherit", "ipc"], | ||
cwd: path.resolve(__dirname, ".."), | ||
} | ||
).on("message", (message) => { | ||
const parsedMessage = JSON.parse(message.toString()); | ||
ip = parsedMessage.ip; | ||
port = parsedMessage.port; | ||
resolveReadyPromise(undefined); | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await readyPromise; | ||
await new Promise((resolve, reject) => { | ||
wranglerProcess.once("exit", (code) => { | ||
if (!code) { | ||
resolve(code); | ||
} else { | ||
reject(code); | ||
} | ||
}); | ||
wranglerProcess.kill("SIGTERM"); | ||
}); | ||
}); | ||
|
||
it.concurrent("mounts a plugin correctly at root", async () => { | ||
await readyPromise; | ||
const response = await fetch(`http://${ip}:${port}/api/v1/instance`); | ||
const text = await response.text(); | ||
expect(text).toMatchInlineSnapshot(`"Response from a nested folder"`); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
fixtures/pages-plugin-mounted-on-root-app/tests/tsconfig.json
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,8 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["node", "jest"] | ||
}, | ||
"include": ["**/*.ts"], | ||
"exclude": [] | ||
} |
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,11 @@ | ||
{ | ||
"include": ["index.d.ts", "functions"], | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"module": "CommonJS", | ||
"lib": ["ES2020"], | ||
"types": ["@cloudflare/workers-types"], | ||
"moduleResolution": "node", | ||
"noEmit": true | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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