Skip to content

Commit

Permalink
fix: add client address provider to adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
juranki committed Mar 17, 2022
1 parent 1cb736f commit b112391
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/adapter/src/files/at-edge-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ export const handler: CloudFrontRequestHandler = async (event, context) => {

log('DEBUG', 'render input', input)

const rendered = await server.respond(input)
const rendered = await server.respond(input, {
getClientAddress() {
const addrHeader = request.headers['cloudfront-viewer-address']
if (addrHeader) {
return addrHeader[0].value.split(':')[0]
}
return ''
},
})

if (rendered) {
log('DEBUG', 'render output', rendered)
Expand Down
1 change: 1 addition & 0 deletions packages/sample-site-v2/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"name": "sample-site-v2",
"version": "0.0.1",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions packages/test/src/routes/my-ip.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
export let clientAddress: string;
</script>

<h1>{clientAddress}</h1>
8 changes: 8 additions & 0 deletions packages/test/src/routes/my-ip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { RequestHandler } from "@sveltejs/kit";

export const get: RequestHandler = async ({ clientAddress }) => {
const body = { clientAddress }
return {
body,
}
}
1 change: 1 addition & 0 deletions packages/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"moduleResolution": "node",
"module": "es2020",
Expand Down

0 comments on commit b112391

Please sign in to comment.