@vercel/functions 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/docs/modules/index.md +3 -3
- package/headers.d.ts +1 -1
- package/headers.js +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/docs/modules/index.md
CHANGED
|
@@ -29,7 +29,7 @@ import { geolocation } from '@vercel/functions';
|
|
|
29
29
|
|
|
30
30
|
export function GET(request) {
|
|
31
31
|
const details = geolocation(request);
|
|
32
|
-
return Response.json(
|
|
32
|
+
return Response.json(details);
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -59,7 +59,7 @@ The location information of the request, in this way:
|
|
|
59
59
|
|
|
60
60
|
#### Defined in
|
|
61
61
|
|
|
62
|
-
[packages/functions/src/headers.ts:
|
|
62
|
+
[packages/functions/src/headers.ts:166](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L166)
|
|
63
63
|
|
|
64
64
|
---
|
|
65
65
|
|
|
@@ -144,7 +144,7 @@ The IP address of the request.
|
|
|
144
144
|
|
|
145
145
|
#### Defined in
|
|
146
146
|
|
|
147
|
-
[packages/functions/src/headers.ts:
|
|
147
|
+
[packages/functions/src/headers.ts:119](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L119)
|
|
148
148
|
|
|
149
149
|
---
|
|
150
150
|
|
package/headers.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ export declare function ipAddress(request: Request): string | undefined;
|
|
|
105
105
|
*
|
|
106
106
|
* export function GET(request) {
|
|
107
107
|
* const details = geolocation(request);
|
|
108
|
-
* return Response.json(
|
|
108
|
+
* return Response.json(details);
|
|
109
109
|
* }
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
package/headers.js
CHANGED
|
@@ -41,6 +41,10 @@ const EMOJI_FLAG_UNICODE_STARTING_POSITION = 127397;
|
|
|
41
41
|
function getHeader(request, key) {
|
|
42
42
|
return request.headers.get(key) ?? void 0;
|
|
43
43
|
}
|
|
44
|
+
function getHeaderWithDecode(request, key) {
|
|
45
|
+
const header = getHeader(request, key);
|
|
46
|
+
return header ? decodeURIComponent(header) : void 0;
|
|
47
|
+
}
|
|
44
48
|
function getFlag(countryCode) {
|
|
45
49
|
const regex = new RegExp("^[A-Z]{2}$").test(countryCode);
|
|
46
50
|
if (!countryCode || !regex)
|
|
@@ -60,7 +64,8 @@ function getRegionFromRequestId(requestId) {
|
|
|
60
64
|
}
|
|
61
65
|
function geolocation(request) {
|
|
62
66
|
return {
|
|
63
|
-
city
|
|
67
|
+
// city name may be encoded to support multi-byte characters
|
|
68
|
+
city: getHeaderWithDecode(request, CITY_HEADER_NAME),
|
|
64
69
|
country: getHeader(request, COUNTRY_HEADER_NAME),
|
|
65
70
|
flag: getFlag(getHeader(request, COUNTRY_HEADER_NAME)),
|
|
66
71
|
countryRegion: getHeader(request, REGION_HEADER_NAME),
|