-
Notifications
You must be signed in to change notification settings - Fork 72
Merge the experimental branch back to main #196
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
Merged
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
9480bfa
feat: add middleware support
vicb eb6badf
feat: import the middleware example
vicb 7e74443
feat: adapt the middleware example for cloudflare
vicb cda60c6
test: add middleware e2e
vicb 05f31da
fix: fix CI errors
vicb 30a68b3
feat: integrate OpenNext static assets (#128)
vicb 6fa3908
chore: update to latest opennextjs/aws
vicb dfb3dff
feat: integrate the OpenNext server
vicb d231b61
refactor: sync with new cloudflare wrapper names
vicb c3c8c6e
refactor: cleanup
vicb c10aabf
fix(build): Do not minify OpenNext bundles (#144)
vicb 03d1c7b
chore: bump @opennextjs/aws (#149)
vicb 132552d
chore(wrangler): bump to ^3.93.0 (#154)
vicb 409065d
feat: rename the binary from "cloudflare" to "opennextjs-cloudflare" …
petebacondarwin 2d98bb0
chore: update opennext/aws (#170)
vicb 5025aa1
Patch the `loadInstrumentationModule` method to support Next.js 15 (#…
dario-piotrowicz 7202a2a
run code quality workflow checks on experimental branch prs (#179)
james-elicx 2322c4d
fix: Request constructor override
vicb 8e6be55
Convert the API example to OpenNext
vicb f300d76
Convert the create next app example to OpenNext
vicb 8d0ce18
Convert the blog example to OpenNext
vicb 1222474
Convert the commerce example to OpenNext
vicb acc37d9
fix: solve __import_unsupported Next.js 15 issue by bumping the `@ope…
dario-piotrowicz 22d7b11
Update `patchFindDir` to work with Next.js 15.1 (#184)
dario-piotrowicz a165433
make sure all code patch steps are validated (#186)
dario-piotrowicz fb64f0f
patch `eval("require")` calls to avoid runtime warnings (#187)
dario-piotrowicz 530f350
prevent eval patch from failing build (#190)
james-elicx 45d8fc2
inline project env files in worker (#181)
james-elicx 7d4da89
Drop tsup in favor of tsc (#192)
vicb 2ece237
fix: No body for 101, 204, 205, or 304 status code (#195)
vicb 2313248
feat: kv cache (#194)
vicb 1ea01d3
style: fix formatting
vicb 935b758
test: disable commerce
vicb 2c0e57a
Update packages/cloudflare/README.md
vicb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
--- | ||
"@opennextjs/cloudflare": minor | ||
--- | ||
|
||
feat: rename the binary from "cloudflare" to "opennextjs-cloudflare" | ||
|
||
**BREAKING CHANGE**: | ||
After this change the old way of running the tool (e.g. `pnpm cloudflare`) no longer works. | ||
Going forward use the new binary name (e.g. `pnpm opennextjs-cloudflare`). | ||
|
||
See [#161](https://github.com/opennextjs/opennextjs-cloudflare/issues/161) |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -3,5 +3,6 @@ node_modules | |
|
||
output | ||
.worker-next | ||
.save.next | ||
.open-next | ||
.wrangler | ||
dist |
This file contains hidden or 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 @@ | ||
NEXTJS_ENV=development |
This file contains hidden or 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 @@ | ||
TEST_ENV_VAR=TEST_VALUE |
This file contains hidden or 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 async function GET() { | ||
return new Response(JSON.stringify(process.env)); | ||
} |
This file contains hidden or 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 hidden or 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,25 @@ | ||
import type { OpenNextConfig } from "@opennextjs/aws/types/open-next"; | ||
|
||
const config: OpenNextConfig = { | ||
default: { | ||
override: { | ||
wrapper: "cloudflare-node", | ||
converter: "edge", | ||
// Unused implementation | ||
incrementalCache: "dummy", | ||
tagCache: "dummy", | ||
queue: "dummy", | ||
}, | ||
}, | ||
|
||
middleware: { | ||
external: true, | ||
override: { | ||
wrapper: "cloudflare-edge", | ||
converter: "edge", | ||
proxyExternalRequest: "fetch", | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
#:schema node_modules/wrangler/config-schema.json | ||
name = "api" | ||
main = ".worker-next/index.mjs" | ||
compatibility_date = "2024-09-16" | ||
compatibility_flags = ["nodejs_compat_v2"] | ||
main = ".open-next/worker.js" | ||
compatibility_date = "2024-09-23" | ||
compatibility_flags = ["nodejs_compat"] | ||
|
||
assets = { directory = ".worker-next/assets", binding = "ASSETS" } | ||
assets = { directory = ".open-next/assets", binding = "ASSETS" } | ||
|
||
[vars] | ||
hello = 'Hello World from the cloudflare context!' |
This file contains hidden or 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,25 @@ | ||
import type { OpenNextConfig } from "@opennextjs/aws/types/open-next"; | ||
|
||
const config: OpenNextConfig = { | ||
default: { | ||
override: { | ||
wrapper: "cloudflare-node", | ||
converter: "edge", | ||
// Unused implementation | ||
incrementalCache: "dummy", | ||
tagCache: "dummy", | ||
queue: "dummy", | ||
}, | ||
}, | ||
|
||
middleware: { | ||
external: true, | ||
override: { | ||
wrapper: "cloudflare-edge", | ||
converter: "edge", | ||
proxyExternalRequest: "fetch", | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#:schema node_modules/wrangler/config-schema.json | ||
name = "create-next-app" | ||
main = ".worker-next/index.mjs" | ||
main = ".open-next/worker.js" | ||
|
||
compatibility_date = "2024-08-29" | ||
compatibility_flags = ["nodejs_compat_v2"] | ||
compatibility_date = "2024-09-23" | ||
compatibility_flags = ["nodejs_compat"] | ||
|
||
# Use the new Workers + Assets to host the static frontend files | ||
assets = { directory = ".worker-next/assets", binding = "ASSETS" } | ||
assets = { directory = ".open-next/assets", binding = "ASSETS" } |
This file contains hidden or 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,42 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
# playwright | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
This file contains hidden or 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,31 @@ | ||
# Middleware | ||
|
||
This example shows how to use [Middleware in Next.js](https://nextjs.org/docs/app/building-your-application/routing/middleware) to run code before a request is completed. | ||
|
||
The index page ([`app/page.tsx`](app/page.tsx)) has a list of links to pages with `redirect`, `rewrite`, or normal behavior. | ||
|
||
On the Middleware file ([`middleware.ts`](middleware.ts)) the routes are already being filtered by defining a `matcher` on the exported config. If you want the Middleware to run for every request, you can remove the `matcher`. | ||
|
||
## Deploy your own | ||
|
||
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example): | ||
|
||
[](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/middleware&project-name=middleware&repository-name=middleware) | ||
|
||
## How to use | ||
|
||
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example: | ||
|
||
```bash | ||
npx create-next-app --example middleware middleware-app | ||
``` | ||
|
||
```bash | ||
yarn create next-app --example middleware middleware-app | ||
``` | ||
|
||
```bash | ||
pnpm create next-app --example middleware middleware-app | ||
``` | ||
|
||
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). |
This file contains hidden or 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 default function AboutPage() { | ||
return <h1>About</h1>; | ||
} |
This file contains hidden or 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 default function About2Page() { | ||
return <h1>About 2</h1>; | ||
} |
This file contains hidden or 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 default function AnotherPage() { | ||
return <h1>Another</h1>; | ||
} |
This file contains hidden or 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,14 @@ | ||
import type { Metadata } from "next"; | ||
|
||
export default function RootLayout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
); | ||
} | ||
|
||
export const metadata: Metadata = { | ||
title: "Next.js Middleware example", | ||
description: "Redirect and rewrite pages using Next.js Middleware.", | ||
}; |
This file contains hidden or 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 default function MiddlewarePage() { | ||
return <h1>Via middleware</h1>; | ||
} |
This file contains hidden or 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 Link from "next/link"; | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<h1>Index</h1> | ||
<p> | ||
<Link href="/about">Go to about page (will redirect)</Link> | ||
</p> | ||
<p> | ||
<Link href="/another">Go to another page (will rewrite)</Link> | ||
</p> | ||
<p> | ||
<Link href="/about2">Go to about 2 page (no redirect or rewrite)</Link> | ||
</p> | ||
<p> | ||
<Link href="/middleware">Go to middleware page (using NextResponse.next())</Link> | ||
</p> | ||
</div> | ||
); | ||
} |
This file contains hidden or 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 default function RedirectedPage() { | ||
return <h1>Redirected from /about</h1>; | ||
} |
This file contains hidden or 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 default function RewritePage() { | ||
return <h1>Rewrite</h1>; | ||
} |
This file contains hidden or 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,29 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test("redirect", async ({ page }) => { | ||
await page.goto("/"); | ||
await page.click('[href="/about"]'); | ||
expect(page.waitForURL("**/redirected")); | ||
expect(await page.textContent("h1")).toContain("Redirected"); | ||
}); | ||
|
||
test("rewrite", async ({ page }) => { | ||
await page.goto("/"); | ||
await page.click('[href="/another"]'); | ||
expect(page.waitForURL("**/another")); | ||
expect(await page.textContent("h1")).toContain("Rewrite"); | ||
}); | ||
|
||
test("no matching middleware", async ({ page }) => { | ||
await page.goto("/"); | ||
await page.click('[href="/about2"]'); | ||
expect(page.waitForURL("**/about2")); | ||
expect(await page.textContent("h1")).toContain("About 2"); | ||
}); | ||
|
||
test("matching noop middleware", async ({ page }) => { | ||
await page.goto("/"); | ||
await page.click('[href="/middleware"]'); | ||
expect(page.waitForURL("**/middleware")); | ||
expect(await page.textContent("h1")).toContain("Via middleware"); | ||
}); |
This file contains hidden or 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,53 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
declare const process: { env: Record<string, string> }; | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./", | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: "html", | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: "http://localhost:8774", | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
|
||
{ | ||
name: "firefox", | ||
use: { ...devices["Desktop Firefox"] }, | ||
}, | ||
|
||
{ | ||
name: "webkit", | ||
use: { ...devices["Desktop Safari"] }, | ||
}, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: "pnpm preview:worker", | ||
url: "http://localhost:8774", | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.