mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
Add back support for Astro.clientAddress to Vercel serverless (#6484)
This commit is contained in:
parent
a2ceee2783
commit
04a84f1684
1 changed files with 7 additions and 2 deletions
|
@ -2,6 +2,8 @@ import type { App } from 'astro/app';
|
||||||
import type { IncomingMessage, ServerResponse } from 'node:http';
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
||||||
import { splitCookiesString } from 'set-cookie-parser';
|
import { splitCookiesString } from 'set-cookie-parser';
|
||||||
|
|
||||||
|
const clientAddressSymbol = Symbol.for('astro.clientAddress');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Credits to the SvelteKit team
|
Credits to the SvelteKit team
|
||||||
https://github.com/sveltejs/kit/blob/8d1ba04825a540324bc003e85f36559a594aadc2/packages/kit/src/exports/node/index.js
|
https://github.com/sveltejs/kit/blob/8d1ba04825a540324bc003e85f36559a594aadc2/packages/kit/src/exports/node/index.js
|
||||||
|
@ -99,13 +101,16 @@ export async function getRequest(
|
||||||
req: IncomingMessage,
|
req: IncomingMessage,
|
||||||
bodySizeLimit?: number
|
bodySizeLimit?: number
|
||||||
): Promise<Request> {
|
): Promise<Request> {
|
||||||
return new Request(base + req.url, {
|
let headers = req.headers as Record<string, string>;
|
||||||
|
let request = new Request(base + req.url, {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
duplex: 'half',
|
duplex: 'half',
|
||||||
method: req.method,
|
method: req.method,
|
||||||
headers: req.headers as Record<string, string>,
|
headers,
|
||||||
body: get_raw_body(req, bodySizeLimit),
|
body: get_raw_body(req, bodySizeLimit),
|
||||||
});
|
});
|
||||||
|
Reflect.set(request, clientAddressSymbol, headers['x-forwarded-for']);
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setResponse(
|
export async function setResponse(
|
||||||
|
|
Loading…
Add table
Reference in a new issue