You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/09-adapters.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,9 +103,9 @@ Within the `adapt` method, there are a number of things that an adapter should d
103
103
- Clear out the build directory
104
104
- Write SvelteKit output with `builder.writeClient`, `builder.writePrerendered`, `builder.writeServer`, and `builder.writeStatic`
105
105
- Output code that:
106
-
- Imports `App` from `${builder.getServerDirectory()}/app.js`
106
+
- Imports `Server` from `${builder.getServerDirectory()}/index.js`
107
107
- Instantiates the app with a manifest generated with `builder.generateManifest({ relativePath })`
108
-
- Listens for requests from the platform, converts them to a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) if necessary, calls the `render` function to generate a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) and responds with it
108
+
- Listens for requests from the platform, converts them to a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) if necessary, calls the `server.respond(request, { getClientAddress })` function to generate a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) and responds with it
109
109
- expose any platform-specific information to SvelteKit via the `platform` option passed to `server.respond`
110
110
- Globally shims `fetch` to work on the target platform, if necessary. SvelteKit provides a `@sveltejs/kit/install-fetch` helper for platforms that can use `node-fetch`
111
111
- Bundle the output to avoid needing to install dependencies on the target platform, if necessary
> [`x-forwarded-proto`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto) and [`x-forwarded-host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host) are de facto standard headers that forward the original protocol and host if you're using a reverse proxy (think load balancers and CDNs). You should only set these variables if you trust the reverse proxy.
65
66
67
+
The [RequestEvent](https://kit.svelte.dev/docs/types#additional-types-requestevent) object passed to hooks and endpoints includes an `event.clientAddress` property representing the client's IP address. By default this is the connecting `remoteAddress`. If your server is behind one or more proxies (such as a load balancer), this value will contain the innermost proxy's IP address rather than the client's, so we need to specify an `ADDRESS_HEADER` to read the address from:
68
+
69
+
```
70
+
ADDRESS_HEADER=True-Client-IP node build
71
+
```
72
+
73
+
> Headers can easily be spoofed. As with `PROTOCOL_HEADER` and `HOST_HEADER`, you should [know what you're doing](https://adam-p.ca/blog/2022/03/x-forwarded-for/) before setting these.
74
+
66
75
All of these environment variables can be changed, if necessary, using the `env` option:
67
76
68
77
```js
@@ -71,6 +80,7 @@ env: {
71
80
port:'MY_PORT_VARIABLE',
72
81
origin:'MY_ORIGINURL',
73
82
headers: {
83
+
address:'MY_ADDRESS_HEADER',
74
84
protocol:'MY_PROTOCOL_HEADER',
75
85
host:'MY_HOST_HEADER'
76
86
}
@@ -84,6 +94,24 @@ MY_ORIGINURL=https://my.site \
84
94
node build
85
95
```
86
96
97
+
### xForwardedForIndex
98
+
99
+
If the `ADDRESS_HEADER` is `X-Forwarded-For`, the header value will contain a comma-separated list of IP addresses. For example, if there are three proxies between your server and the client, proxy 3 will forward the addresses of the client and the first two proxies:
For that reason you should always use a negative number (depending on the number of proxies) if you need to trust `event.clientAddress`. In the above example, `0` would yield the spoofed address while `-3` would continue to work.
114
+
87
115
## Custom server
88
116
89
117
The adapter creates two files in your build directory — `index.js` and `handler.js`. Running `index.js` — e.g. `node build`, if you use the default build directory — will start a server on the configured port.
0 commit comments