summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/src
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2023-04-06 15:40:50 -0400
committerGravatar GitHub <noreply@github.com> 2023-04-06 15:40:50 -0400
commit416ceb9730ce604cd3f73c22200907d9b9978073 (patch)
treec05247973cbf96690cedda280a0250a4b8669ce8 /packages/integrations/netlify/src
parent9e88e0f23c5913c07f7e3e96fa0555219ef710dc (diff)
downloadastro-416ceb9730ce604cd3f73c22200907d9b9978073.tar.gz
astro-416ceb9730ce604cd3f73c22200907d9b9978073.tar.zst
astro-416ceb9730ce604cd3f73c22200907d9b9978073.zip
Use Deno API to set Astro.clientAddress (#6651)
* Use Deno API to set Astro.clientAddress * Add types
Diffstat (limited to 'packages/integrations/netlify/src')
-rw-r--r--packages/integrations/netlify/src/netlify-edge-functions.ts7
1 files changed, 5 insertions, 2 deletions
diff --git a/packages/integrations/netlify/src/netlify-edge-functions.ts b/packages/integrations/netlify/src/netlify-edge-functions.ts
index f4766b276..8011e2b1b 100644
--- a/packages/integrations/netlify/src/netlify-edge-functions.ts
+++ b/packages/integrations/netlify/src/netlify-edge-functions.ts
@@ -1,4 +1,5 @@
import type { SSRManifest } from 'astro';
+import type { Context } from '@netlify/edge-functions';
import { App } from 'astro/app';
const clientAddressSymbol = Symbol.for('astro.clientAddress');
@@ -6,7 +7,7 @@ const clientAddressSymbol = Symbol.for('astro.clientAddress');
export function createExports(manifest: SSRManifest) {
const app = new App(manifest);
- const handler = async (request: Request): Promise<Response | void> => {
+ const handler = async (request: Request, context: Context): Promise<Response | void> => {
const url = new URL(request.url);
// If this matches a static asset, just return and Netlify will forward it
@@ -15,7 +16,9 @@ export function createExports(manifest: SSRManifest) {
return;
}
if (app.match(request)) {
- const ip = request.headers.get('x-nf-client-connection-ip');
+ const ip = request.headers.get('x-nf-client-connection-ip')
+ || context?.ip
+ || (context as any)?.remoteAddr?.hostname;
Reflect.set(request, clientAddressSymbol, ip);
const response = await app.render(request);
if (app.setCookieHeaders) {