packages/edge/docs/README.md
• Const CITY_HEADER_NAME: "x-vercel-ip-city"
City of the original client IP as calculated by Vercel Proxy.
packages/functions/headers.d.ts:4
• Const COUNTRY_HEADER_NAME: "x-vercel-ip-country"
Country of the original client IP as calculated by Vercel Proxy.
packages/functions/headers.d.ts:8
• Const EMOJI_FLAG_UNICODE_STARTING_POSITION: 127397
Unicode characters for emoji flags start at this number, and run up to 127469.
packages/functions/headers.d.ts:38
• Const IP_HEADER_NAME: "x-real-ip"
Client IP as calculated by Vercel Proxy.
packages/functions/headers.d.ts:12
• Const LATITUDE_HEADER_NAME: "x-vercel-ip-latitude"
Latitude of the original client IP as calculated by Vercel Proxy.
packages/functions/headers.d.ts:16
• Const LONGITUDE_HEADER_NAME: "x-vercel-ip-longitude"
Longitude of the original client IP as calculated by Vercel Proxy.
packages/functions/headers.d.ts:20
• Const POSTAL_CODE_HEADER_NAME: "x-vercel-ip-postal-code"
Postal code of the original client IP as calculated by Vercel Proxy.
packages/functions/headers.d.ts:30
• Const REGION_HEADER_NAME: "x-vercel-ip-country-region"
Country region of the original client IP calculated by Vercel Proxy.
See docs.
packages/functions/headers.d.ts:26
• Const REQUEST_ID_HEADER_NAME: "x-vercel-id"
The request ID for each request generated by Vercel Proxy.
packages/functions/headers.d.ts:34
▸ geolocation(request): Geo
Returns the location information for the incoming request.
Example
import { geolocation } from '@vercel/functions';
export function GET(request) {
const details = geolocation(request);
return Response.json(details);
}
| Name | Type | Description |
|---|---|---|
request | Request | The incoming request object which provides the geolocation data |
The location information of the request, in this way:
{
"city": "New York",
"country": "US",
"flag": "🇺🇸",
"countryRegion": "NY",
"region": "iad1",
"latitude": "40.7128",
"longitude": "-74.0060"
"postalCode": "10001"
}
packages/functions/headers.d.ts:125
▸ ipAddress(input): string | undefined
Returns the IP address of the request from the headers.
Example
import { ipAddress } from '@vercel/functions';
export function GET(request) {
const ip = ipAddress(request);
return new Response(`Your IP is ${ip}`);
}
| Name | Type | Description |
|---|---|---|
input | Request | Headers | The incoming request object or headers. |
string | undefined
The IP address of the request.
packages/functions/headers.d.ts:95
▸ next(init?): Response
Returns a Response that instructs the system to continue processing the request.
Example
import { next } from '@vercel/edge';
export default function middleware(_req: Request) {
return next();
}
Example
import { next } from '@vercel/edge';
export default function middleware(_req: Request) {
return next({
headers: { 'x-from-middleware': 'true' },
});
}
| Name | Type | Description |
|---|---|---|
init? | ExtraResponseInit | Additional options for the response |
packages/functions/middleware.d.ts:110
▸ rewrite(destination, init?): Response
Returns a response that rewrites the request to a different URL.
Example
import { rewrite, next } from '@vercel/edge';
export default async function middleware(req: Request) {
const flagged = await getFlag(req, 'isExperimental');
if (flagged) {
const url = new URL(req.url);
url.pathname = `/experimental{url.pathname}`;
return rewrite(url);
}
return next();
}
Example
import { rewrite, next } from '@vercel/edge';
export default function middleware(req: Request) {
const auth = checkJwt(req.headers.get('Authorization'));
if (!checkJwt) {
return rewrite(new URL('/api/error-unauthorized', req.url));
}
const url = new URL(req.url);
url.searchParams.set('_userId', auth.userId);
return rewrite(url);
}
export const config = { matcher: '/api/users/:path*' };
| Name | Type | Description |
|---|---|---|
destination | string | URL | new URL to rewrite the request to |
init? | ExtraResponseInit | Additional options for the response |
packages/functions/middleware.d.ts:80