Skip to content

Commit 7756af1

Browse files
committed
add x-forwarded-host
1 parent 8c7eb37 commit 7756af1

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Please raise an issue on [Github](https://github.com/yarbsemaj/sveltekit-adapter
4545
## Versions
4646
| Adapter Version| Sveltekit Version |
4747
| ---------------| ----------------- |
48+
| 1.1.x | 1.22.0 (Official) |
4849
| 1.x.x | 1.0.0 (Official) |
4950
| 0.12.x | 1.0.0-next.433 |
5051
| 0.11.x | 1.0.0-next.401 |

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yarbsemaj/adapter-lambda",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"license": "MIT",
55
"description": "An adapter for [SvelteKit](https://kit.svelte.dev/) for AWS Lambda via Lambda Proxy and API Gateway. [Serverless](https://www.serverless.com/) deployment.",
66
"repository": {

serverless.yml

+19
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,26 @@ resources:
124124
- HEAD
125125
- OPTIONS
126126
ForwardedValues:
127+
Headers:
128+
- x-forwarded-host
127129
Cookies:
128130
Forward: all
129131
QueryString: True
130132
ViewerProtocolPolicy: 'redirect-to-https'
133+
FunctionAssociations:
134+
- EventType: viewer-request
135+
FunctionARN: !GetAtt XForwardFunction.FunctionMetadata.FunctionARN
136+
137+
XForwardFunction:
138+
Type: AWS::CloudFront::Function
139+
Properties:
140+
AutoPublish: true
141+
Name: "${self:provider.stage}-${self:service}-XForwardFunction"
142+
FunctionCode: !Sub |
143+
function handler(event) {
144+
event.request.headers['x-forwarded-host'] = event.request.headers['host']
145+
return event.request
146+
}
147+
FunctionConfig:
148+
Comment: 'Add x-forwarded-host'
149+
Runtime: cloudfront-js-1.0

src/serverless.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ export async function handler(event, context) {
77
const { rawPath, headers, rawQueryString, body, requestContext, isBase64Encoded, cookies } = event;
88

99
const encoding = isBase64Encoded ? 'base64' : headers['content-encoding'] || 'utf-8';
10+
const domainName = headers['x-forwarded-host']
1011
const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
1112

1213
if (cookies) {
1314
headers['cookie'] = cookies.join('; ')
1415
}
1516

16-
let rawURL = `https://${requestContext.domainName}${rawPath}${rawQueryString ? `?${rawQueryString}` : ''}`
17+
let rawURL = `https://${domainName}${rawPath}${rawQueryString ? `?${rawQueryString}` : ''}`
1718

1819
await app.init({
1920
env: process.env

0 commit comments

Comments
 (0)