Skip to content

Commit

Permalink
Adds support for Astro.clientAddress (#3973)
Browse files Browse the repository at this point in the history
* Adds support for Astro.clientAddress

* Pass through mode and adapterName in SSG

* Pass through the mode provided

* Provide an adapter specific error message when possible
  • Loading branch information
matthewp authored Jul 19, 2022
1 parent f5bf583 commit 72fbabf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/integrations/netlify/src/netlify-edge-functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { SSRManifest } from 'astro';
import { App } from 'astro/app';

const clientAddressSymbol = Symbol.for('astro.clientAddress');

export function createExports(manifest: SSRManifest) {
const app = new App(manifest);

Expand All @@ -13,6 +15,8 @@ export function createExports(manifest: SSRManifest) {
return;
}
if (app.match(request)) {
const ip = request.headers.get('x-nf-client-connection-ip');
Reflect.set(request, clientAddressSymbol, ip);
return app.render(request);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/integrations/netlify/src/netlify-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function parseContentType(header?: string) {
return header?.split(';')[0] ?? '';
}

const clientAddressSymbol = Symbol.for('astro.clientAddress');

export const createExports = (manifest: SSRManifest, args: Args) => {
const app = new App(manifest);

Expand Down Expand Up @@ -71,6 +73,9 @@ export const createExports = (manifest: SSRManifest, args: Args) => {
};
}

const ip = headers['x-nf-client-connection-ip'];
Reflect.set(request, clientAddressSymbol, ip);

const response: Response = await app.render(request);
const responseHeaders = Object.fromEntries(response.headers.entries());

Expand Down

0 comments on commit 72fbabf

Please sign in to comment.