Skip to content

Commit d80c931

Browse files
authored
Merge branch 'main' into tn-advMiddlewareRewriteInit
2 parents 5369c26 + 9c6ec9f commit d80c931

File tree

19 files changed

+2539
-30
lines changed

19 files changed

+2539
-30
lines changed

.github/workflows/add-to-project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
steps:
1010
- name: Generate token
1111
id: generate_token
12-
uses: tibdex/github-app-token@v1.5.2
12+
uses: tibdex/github-app-token@v1.8.0
1313
with:
1414
app_id: ${{ secrets.TOKENS_APP_ID }}
1515
private_key: ${{ secrets.TOKENS_PRIVATE_KEY }}

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.20.0
1+
16.20.1

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"packages/runtime": "4.38.1",
3-
"packages/next": "1.4.7"
3+
"packages/next": "1.4.8"
44
}

cypress/e2e/middleware/standard.cy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ describe('Standard middleware', () => {
4545
expect(response.headers).to.have.property('x-foo', 'bar')
4646
})
4747
})
48+
49+
it('preserves locale on rewrites (skipMiddlewareUrlNormalize: true)', () => {
50+
cy.visit('/de-de/locale-preserving-rewrite')
51+
cy.get('div').should('contain', 'Locale: de-DE')
52+
cy.url().should('eq', `${Cypress.config().baseUrl}/de-de/locale-preserving-rewrite`)
53+
})
4854
})
4955

5056
describe('Middleware matchers', () => {

demos/middleware/middleware.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export async function middleware(req: NextRequest) {
2121
}
2222

2323
const request = new MiddlewareRequest(req)
24-
if (pathname.startsWith('/static')) {
24+
25+
// skipMiddlewareUrlNormalize next config option is used so we have to try to match both html path and data blob path
26+
if (pathname.startsWith('/static') || pathname.endsWith('/static.json')) {
2527
// Unlike NextResponse.next(), this actually sends the request to the origin
2628
const res = await request.next()
2729
const message = `This was static (& escaping test &) but has been transformed in ${req.geo?.city}`
@@ -36,7 +38,8 @@ export async function middleware(req: NextRequest) {
3638
return res
3739
}
3840

39-
if (pathname.startsWith('/request-rewrite')) {
41+
// skipMiddlewareUrlNormalize next config option is used so we have to try to match both html path and data blob path
42+
if (pathname.startsWith('/request-rewrite') || pathname.endsWith('/request-rewrite.json')) {
4043
// request.rewrite() should return the MiddlewareResponse object instead of the Response object.
4144
const res = await request.rewrite('/static-rewrite',
4245
{
@@ -106,6 +109,10 @@ export async function middleware(req: NextRequest) {
106109
return response
107110
}
108111

112+
if (pathname.includes('locale-preserving-rewrite')) {
113+
return NextResponse.rewrite(new URL('/locale-test', req.url))
114+
}
115+
109116
if (pathname.startsWith('/shows')) {
110117
if (pathname.startsWith('/shows/222')) {
111118
response = NextResponse.next()
@@ -157,6 +164,7 @@ export const config = {
157164
matcher: [
158165
'/api/:all*',
159166
'/headers',
167+
'/:all*/locale-preserving-rewrite',
160168
'/cookies/:path*',
161169
{ source: '/static' },
162170
{source: '/request-rewrite' },

demos/middleware/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const nextConfig = {
1111
defaultLocale: 'en',
1212
locales: ['en', 'de-DE'],
1313
},
14+
skipMiddlewareUrlNormalize: true,
1415
}
1516

1617
module.exports = nextConfig

demos/middleware/pages/locale-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react'
2+
3+
const Page = ({ pageLocale }) => {
4+
return <div>Locale: {pageLocale}</div>
5+
}
6+
7+
export async function getServerSideProps({ locale }) {
8+
return {
9+
props: {
10+
pageLocale: locale,
11+
},
12+
}
13+
}
14+
15+
export default Page

demos/nx-next-monorepo-demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"@testing-library/react": "13.4.0",
3131
"@types/jest": "28.1.8",
3232
"@types/node": "16.18.36",
33-
"@types/react": "18.0.38",
34-
"@types/react-dom": "18.0.11",
33+
"@types/react": "18.2.14",
34+
"@types/react-dom": "18.2.6",
3535
"@typescript-eslint/eslint-plugin": "^5.36.1",
3636
"@typescript-eslint/parser": "^5.36.1",
3737
"babel-jest": "28.1.3",

demos/turborepo-next-monorepo-demo/apps/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"devDependencies": {
1818
"@babel/core": "^7.0.0",
1919
"@types/node": "^17.0.12",
20-
"@types/react": "18.0.38",
20+
"@types/react": "18.2.14",
2121
"eslint": "7.32.0",
2222
"eslint-config-custom": "*",
2323
"next-transpile-modules": "9.0.0",

demos/turborepo-next-monorepo-demo/apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"devDependencies": {
1818
"@babel/core": "^7.0.0",
1919
"@types/node": "^17.0.12",
20-
"@types/react": "18.0.38",
20+
"@types/react": "18.2.14",
2121
"eslint": "7.32.0",
2222
"eslint-config-custom": "*",
2323
"next-transpile-modules": "9.0.0",

demos/turborepo-next-monorepo-demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
"react": "^18.2.0",
2828
"react-dom": "^18.2.0"
2929
},
30-
"packageManager": "npm@8.11.0"
30+
"packageManager": "npm@8.19.4"
3131
}

0 commit comments

Comments
 (0)