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/20-core-concepts/10-routing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -277,7 +277,7 @@ Like `+layout.js`, `+layout.server.js` can export [page options](page-options)
277
277
278
278
## +server
279
279
280
-
As well as pages, you can define routes with a `+server.js` file (sometimes referred to as an 'API route' or an 'endpoint'), which gives you full control over the response. Your `+server.js` file exports functions corresponding to HTTP verbs like `GET`, `POST`, `PATCH`, `PUT`, `DELETE`, `OPTIONS`, and `HEAD` that take a `RequestEvent` argument and return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object.
280
+
As well as pages, you can define routes with a `+server.js` file (sometimes referred to as an 'API route' or an 'endpoint'), which gives you full control over the response. Your `+server.js` file exports functions corresponding to HTTP verbs like `GET`, `POST`, `PATCH`, `PUT`, `DELETE`, `OPTIONS`, and `HEAD` that take a [`RequestEvent`](@sveltejs-kit#RequestEvent) argument and return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object.
281
281
282
282
For example we could create an `/api/random-number` route with a `GET` handler:
Copy file name to clipboardExpand all lines: documentation/docs/25-build-and-deploy/40-adapter-node.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
@@ -34,7 +34,7 @@ Development dependencies will be bundled into your app using [Rollup](https://ro
34
34
35
35
### Compressing responses
36
36
37
-
You will typically want to compress responses coming from the server. If you are already deploying your server behind a reverse proxy for SSL or load balancing, it typically results in better performance to also handle compression at that layer since Node.js is single-threaded.
37
+
You will typically want to compress responses coming from the server. If you're already deploying your server behind a reverse proxy for SSL or load balancing, it typically results in better performance to also handle compression at that layer since Node.js is single-threaded.
38
38
39
39
However, if you're building a [custom server](#Custom-server) and do want to add a compression middleware there, note that we would recommend using [`@polka/compression`](https://www.npmjs.com/package/@polka/compression) since SvelteKit streams responses and the more popular `compression` package does not support streaming and may cause errors when used.
40
40
@@ -101,7 +101,7 @@ If `adapter-node` can't correctly determine the URL of your deployment, you may
101
101
102
102
### `ADDRESS_HEADER` and `XFF_DEPTH`
103
103
104
-
The [RequestEvent](@sveltejs-kit#RequestEvent) object passed to hooks and endpoints includes an `event.getClientAddress()` function that returns 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:
104
+
The [`RequestEvent`](@sveltejs-kit#RequestEvent) object passed to hooks and endpoints includes an `event.getClientAddress()` function that returns 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:
Copy file name to clipboardExpand all lines: documentation/docs/25-build-and-deploy/99-writing-adapters.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ Within the `adapt` method, there are a number of things that an adapter should d
51
51
- Output code that:
52
52
- Imports `Server` from `${builder.getServerDirectory()}/index.js`
53
53
- Instantiates the app with a manifest generated with `builder.generateManifest({ relativePath })`
54
-
- 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
54
+
- 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
55
55
- expose any platform-specific information to SvelteKit via the `platform` option passed to `server.respond`
56
56
- Globally shims `fetch` to work on the target platform, if necessary. SvelteKit provides a `@sveltejs/kit/node/polyfills` helper for platforms that can use `undici`
57
57
- Bundle the output to avoid needing to install dependencies on the target platform, if necessary
Copy file name to clipboardExpand all lines: documentation/docs/30-advanced/20-hooks.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
@@ -106,7 +106,7 @@ Note that `resolve(...)` will never throw an error, it will always return a `Pro
106
106
107
107
### handleFetch
108
108
109
-
This function allows you to modify (or replace) a `fetch` request that happens inside a `load`or `action` function that runs on the server (or during pre-rendering).
109
+
This function allows you to modify (or replace) a `fetch` request that happens inside a `load`, `action`or `handle` function that runs on the server (or during prerendering).
110
110
111
111
For example, your `load` function might make a request to a public URL like `https://api.yourapp.com` when the user performs a client-side navigation to the respective page, but during SSR it might make sense to hit the API directly (bypassing whatever proxies and load balancers sit between it and the public internet).
112
112
@@ -153,7 +153,7 @@ The following can be added to `src/hooks.server.js` _and_ `src/hooks.client.js`:
153
153
154
154
### handleError
155
155
156
-
If an [unexpected error](errors#Unexpected-errors) is thrown during loadingor rendering, this function will be called with the `error`, `event`, `status` code and `message`. This allows for two things:
156
+
If an [unexpected error](errors#Unexpected-errors) is thrown during loading, rendering, or from an endpoint, this function will be called with the `error`, `event`, `status` code and `message`. This allows for two things:
157
157
158
158
- you can log the error
159
159
- you can generate a custom representation of the error that is safe to show to users, omitting sensitive details like messages and stack traces. The returned value, which defaults to `{ message }`, becomes the value of `$page.error`.
Copy file name to clipboardExpand all lines: packages/adapter-auto/index.js
+13-2Lines changed: 13 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -122,9 +122,20 @@ export default () => ({
122
122
},
123
123
supports: {
124
124
read: ()=>{
125
-
thrownewError(
126
-
"The read function imported from $app/server only works in certain environments. Since you're using @sveltejs/adapter-auto, SvelteKit cannot determine whether it will work when your app is deployed. Please replace it with an adapter tailored to your target environment."
125
+
supports_error(
126
+
'The read function imported from $app/server only works in certain environments'
127
127
);
128
128
}
129
129
}
130
130
});
131
+
132
+
/**
133
+
* @param {string} message
134
+
* @returns {never}
135
+
* @throws {Error}
136
+
*/
137
+
functionsupports_error(message){
138
+
thrownewError(
139
+
`${message}. Since you're using @sveltejs/adapter-auto, SvelteKit cannot determine whether it will work when your app is deployed. Please replace it with an adapter tailored to your target environment.`
* Creates an `Emulator`, which allows the adapter to influence the environment
50
-
* during dev, build and prerendering
50
+
* during dev, build and prerendering.
51
51
*/
52
52
emulate?: ()=>MaybePromise<Emulator>;
53
53
}
@@ -790,7 +790,7 @@ export type HandleClientError = (input: {
790
790
})=>MaybePromise<void|App.Error>;
791
791
792
792
/**
793
-
* The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleFetch) hook allows you to modify (or replace) a `fetch` request that happens inside a `load` function that runs on the server (or during pre-rendering)
793
+
* The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleFetch) hook allows you to modify (or replace) a `fetch` request that happens inside a `load` function that runs on the server (or during prerendering).
* The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleFetch) hook allows you to modify (or replace) a `fetch` request that happens inside a `load` function that runs on the server (or during pre-rendering)
775
+
* The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleFetch) hook allows you to modify (or replace) a `fetch` request that happens inside a `load` function that runs on the server (or during prerendering).
0 commit comments