Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/next-on-pages/templates/_worker.js/routes-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ export class RoutesMatcher {
applySearchParams(this.searchParams, newUrl.searchParams);

resp.headers.delete(rewriteKey);

// Honor the status code set by the middleware.
this.status = resp.status;
}

const middlewareNextKey = 'x-middleware-next';
Expand Down
13 changes: 13 additions & 0 deletions pages-e2e/features/issue945/issue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, test } from 'vitest';

describe('issue-945', () => {
test('that we honor status set in nextjs rewrite', async ({ expect }) => {
const response = await fetch(`${DEPLOYMENT_URL}?rewrite=1`);
expect(response.status).toBe(401);
});

test('that a new nextresponse sets our custom status', async ({ expect }) => {
const response = await fetch(`${DEPLOYMENT_URL}`);
expect(response.status).toBe(403);
});
});
3 changes: 3 additions & 0 deletions pages-e2e/features/issue945/main.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"setup": "node --loader tsm setup.ts"
}
1 change: 1 addition & 0 deletions pages-e2e/features/issue945/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// no setup required
2 changes: 1 addition & 1 deletion pages-e2e/fixtures/appLatest/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
echo "{}" > package.json

# Create an app application in the application sub-directory (since the next cli complains if the target directory is not empty)
npx create-next-app@latest application appLatest --ts --no-eslint --no-tailwind --no-src-dir --app --import-alias '@/*'
npx create-next-app@latest application appLatest --ts --no-eslint --no-tailwind --no-turbopack --no-src-dir --app --import-alias '@/*'

# Move everything back in the current directory (so that we follow the same structure as the other fixtures
# and don't break copyWorkspaceAssets)
Expand Down
2 changes: 1 addition & 1 deletion pages-e2e/fixtures/appLatestNoNodeJsCompat/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
echo "{}" > package.json

# Create an app application in the application sub-directory (since the next cli complains if the target directory is not empty)
npx create-next-app@latest application appLatest --ts --no-eslint --no-tailwind --no-src-dir --app --import-alias '@/*'
npx create-next-app@latest application appLatest --ts --no-eslint --no-tailwind --no-turbopack --no-src-dir --app --import-alias '@/*'

# Move everything back in the current directory (so that we follow the same structure as the other fixtures
# and don't break copyWorkspaceAssets)
Expand Down
36 changes: 36 additions & 0 deletions pages-e2e/fixtures/issue945App/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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
40 changes: 40 additions & 0 deletions pages-e2e/fixtures/issue945App/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
11 changes: 11 additions & 0 deletions pages-e2e/fixtures/issue945App/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
7 changes: 7 additions & 0 deletions pages-e2e/fixtures/issue945App/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Home() {
return (
<main>
<h1>home page</h1>
</main>
);
}
12 changes: 12 additions & 0 deletions pages-e2e/fixtures/issue945App/main.fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"features": [
"issue945"
],
"buildConfig": {
"buildCommand": "npx --force ../../../packages/next-on-pages",
"buildOutputDirectory": ".vercel/output/static"
},
"deploymentConfig": {
"compatibilityFlags": ["nodejs_compat"]
}
}
9 changes: 9 additions & 0 deletions pages-e2e/fixtures/issue945App/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { NextRequest, NextResponse } from 'next/server';

export async function middleware(req: NextRequest) {
if (req.url.includes('?rewrite=1')) {
return NextResponse.rewrite(req.url, { status: 401 });
}

return new NextResponse('TEST', { status: 403 });
}
6 changes: 6 additions & 0 deletions pages-e2e/fixtures/issue945App/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};

export default nextConfig;
Loading