Skip to content

Commit b387a42

Browse files
committed
Merge branch 'main' into mk/all-the-tests
2 parents 8d82ad5 + 7323c68 commit b387a42

File tree

14 files changed

+158
-101
lines changed

14 files changed

+158
-101
lines changed

.release-please-manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"packages/runtime": "4.29.1",
3-
"packages/next": "1.4.0"
2+
"packages/runtime": "4.29.2",
3+
"packages/next": "1.4.1"
44
}

cypress/integration/middleware/enhanced.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ describe('Enhanced middleware', () => {
2525
.that.includes('This was static but has been transformed in')
2626
})
2727
})
28+
29+
it('adds geo data', () => {
30+
cy.request('/api/geo').then((response) => {
31+
expect(response.body).to.have.nested.property('headers.x-geo-country')
32+
expect(response.body).to.have.nested.property('headers.x-geo-region')
33+
expect(response.body).to.have.nested.property('headers.x-geo-city')
34+
expect(response.body).to.have.nested.property('headers.x-geo-longitude')
35+
expect(response.body).to.have.nested.property('headers.x-geo-latitude')
36+
expect(response.body).to.have.nested.property('headers.x-geo-timezone')
37+
})
38+
})
2839
})

demos/middleware/middleware.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { NextResponse } from 'next/server'
2-
import type { NextRequest } from 'next/server'
3-
4-
import { MiddlewareRequest } from '@netlify/next'
2+
import { MiddlewareRequest, NextRequest } from '@netlify/next'
53

64
export async function middleware(req: NextRequest) {
75
let response
@@ -29,6 +27,17 @@ export async function middleware(req: NextRequest) {
2927
return request.next()
3028
}
3129

30+
if (pathname.startsWith('/api/geo')) {
31+
req.headers.set('x-geo-country', req.geo.country)
32+
req.headers.set('x-geo-region', req.geo.region)
33+
req.headers.set('x-geo-city', req.geo.city)
34+
req.headers.set('x-geo-longitude', req.geo.longitude)
35+
req.headers.set('x-geo-latitude', req.geo.latitude)
36+
req.headers.set('x-geo-timezone', req.geo.timezone)
37+
38+
return request.next()
39+
}
40+
3241
if (pathname.startsWith('/headers')) {
3342
// Add a header to the rewritten request
3443
req.headers.set('x-hello', 'world')

demos/middleware/pages/api/geo.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function handler(req, res) {
2+
res.status(200).json({ name: 'geo-test', headers: req.headers })
3+
}

package-lock.json

+89-89
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@babel/preset-env": "^7.15.8",
5151
"@babel/preset-typescript": "^7.16.0",
5252
"@delucis/if-env": "^1.1.2",
53-
"@netlify/build": "^28.1.14",
53+
"@netlify/build": "^28.2.2",
5454
"@netlify/eslint-config-node": "^7.0.0",
5555
"@testing-library/cypress": "^8.0.1",
5656
"@types/fs-extra": "^9.0.13",

packages/next/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [1.4.1](https://github.com/netlify/next-runtime/compare/next-v1.4.0...next-v1.4.1) (2022-11-21)
4+
5+
6+
### Bug Fixes
7+
8+
* add longitude, latitude, and timezone to RequestData.geo ([#1777](https://github.com/netlify/next-runtime/issues/1777)) ([3f35549](https://github.com/netlify/next-runtime/commit/3f355497f02726a54aa0b5f391c3e9684d45228f))
9+
310
## [1.4.0](https://github.com/netlify/next-runtime/compare/next-v1.3.1...next-v1.4.0) (2022-10-25)
411

512

packages/next/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netlify/next",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Enhanced Next.js features on Netlify",
55
"main": "lib/index.js",
66
"files": [

packages/next/src/middleware/request.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import type { NextURL } from 'next/dist/server/web/next-url'
22
import { NextResponse } from 'next/server'
3-
import type { NextRequest } from 'next/server'
3+
import type { NextRequest as InternalNextRequest } from 'next/server'
44

55
import { MiddlewareResponse } from './response'
66

7+
export type NextRequest = InternalNextRequest & {
8+
get geo(): {
9+
timezone?: string
10+
}
11+
}
12+
713
export interface NextOptions {
814
/**
915
* Include conditional request headers in the request to the origin.

packages/next/test/request.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ describe('MiddlewareRequest', () => {
2525
code: chance.province(),
2626
},
2727
city: chance.city(),
28+
latitude: chance.latitude(),
29+
longitude: chance.longitude(),
30+
timezone: chance.timezone(),
2831
},
2932
ip,
3033
}
@@ -33,6 +36,9 @@ describe('MiddlewareRequest', () => {
3336
country: context.geo.country?.code,
3437
region: context.geo.subdivision?.code,
3538
city: context.geo.city,
39+
latitude: context.geo.latitude?.toString(),
40+
longitude: context.geo.longitude?.toString(),
41+
timezone: context.geo.timezone,
3642
}
3743

3844
const req = new URL(url)

packages/runtime/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [4.29.2](https://github.com/netlify/next-runtime/compare/plugin-nextjs-v4.29.1...plugin-nextjs-v4.29.2) (2022-11-21)
4+
5+
6+
### Bug Fixes
7+
8+
* add longitude, latitude, and timezone to RequestData.geo ([#1777](https://github.com/netlify/next-runtime/issues/1777)) ([3f35549](https://github.com/netlify/next-runtime/commit/3f355497f02726a54aa0b5f391c3e9684d45228f))
9+
* resolve all pages using nft ([#1780](https://github.com/netlify/next-runtime/issues/1780)) ([267ff0b](https://github.com/netlify/next-runtime/commit/267ff0b5ecf5d9fe5154955542887d9c0c573b85))
10+
311
## [4.29.1](https://github.com/netlify/next-runtime/compare/plugin-nextjs-v4.29.0...plugin-nextjs-v4.29.1) (2022-11-14)
412

513

packages/runtime/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netlify/plugin-nextjs",
3-
"version": "4.29.1",
3+
"version": "4.29.2",
44
"description": "Run Next.js seamlessly on Netlify",
55
"main": "index.js",
66
"files": [
@@ -36,7 +36,7 @@
3636
},
3737
"devDependencies": {
3838
"@delucis/if-env": "^1.1.2",
39-
"@netlify/build": "^28.1.14",
39+
"@netlify/build": "^28.2.2",
4040
"@types/fs-extra": "^9.0.13",
4141
"@types/jest": "^27.4.1",
4242
"@types/merge-stream": "^1.1.2",

packages/runtime/src/templates/edge/next-dev.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ const handler = async (req, context) => {
4343
return
4444
}
4545

46-
// This is the format expected by Next.js
46+
// This is the format expected by Next.js along with the timezone which we support.
4747
const geo = {
4848
country: context.geo.country?.code,
4949
region: context.geo.subdivision?.code,
5050
city: context.geo.city,
51+
latitude: context.geo.latitude?.toString(),
52+
longitude: context.geo.longitude?.toString(),
53+
timezone: context.geo.timezone,
5154
}
5255

5356
// A default request id is fine locally

packages/runtime/src/templates/edge/runtime.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface RequestData {
2020
region?: string
2121
latitude?: string
2222
longitude?: string
23+
timezone?: string
2324
}
2425
headers: Record<string, string>
2526
ip?: string
@@ -63,10 +64,13 @@ const handler = async (req: Request, context: Context) => {
6364
return
6465
}
6566

66-
const geo = {
67+
const geo: RequestData['geo'] = {
6768
country: context.geo.country?.code,
6869
region: context.geo.subdivision?.code,
6970
city: context.geo.city,
71+
latitude: context.geo.latitude?.toString(),
72+
longitude: context.geo.longitude?.toString(),
73+
timezone: context.geo.timezone,
7074
}
7175

7276
const requestId = req.headers.get('x-nf-request-id')

0 commit comments

Comments
 (0)