Skip to content

Commit 7bb41aa

Browse files
authored
minor doc tweaks etc (#13767)
1 parent 9995cf5 commit 7bb41aa

File tree

10 files changed

+36
-25
lines changed

10 files changed

+36
-25
lines changed

documentation/docs/20-core-concepts/10-routing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ Like `+layout.js`, `+layout.server.js` can export [page options](page-options)
277277

278278
## +server
279279

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.
281281

282282
For example we could create an `/api/random-number` route with a `GET` handler:
283283

documentation/docs/25-build-and-deploy/40-adapter-node.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Development dependencies will be bundled into your app using [Rollup](https://ro
3434

3535
### Compressing responses
3636

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.
3838

3939
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.
4040

@@ -101,7 +101,7 @@ If `adapter-node` can't correctly determine the URL of your deployment, you may
101101
102102
### `ADDRESS_HEADER` and `XFF_DEPTH`
103103

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:
105105

106106
```
107107
ADDRESS_HEADER=True-Client-IP node build

documentation/docs/25-build-and-deploy/99-writing-adapters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Within the `adapt` method, there are a number of things that an adapter should d
5151
- Output code that:
5252
- Imports `Server` from `${builder.getServerDirectory()}/index.js`
5353
- 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
5555
- expose any platform-specific information to SvelteKit via the `platform` option passed to `server.respond`
5656
- 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`
5757
- Bundle the output to avoid needing to install dependencies on the target platform, if necessary

documentation/docs/30-advanced/20-hooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Note that `resolve(...)` will never throw an error, it will always return a `Pro
106106

107107
### handleFetch
108108

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).
110110

111111
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).
112112

@@ -153,7 +153,7 @@ The following can be added to `src/hooks.server.js` _and_ `src/hooks.client.js`:
153153

154154
### handleError
155155

156-
If an [unexpected error](errors#Unexpected-errors) is thrown during loading or 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:
157157

158158
- you can log the error
159159
- 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`.

packages/adapter-auto/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,20 @@ export default () => ({
122122
},
123123
supports: {
124124
read: () => {
125-
throw new Error(
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'
127127
);
128128
}
129129
}
130130
});
131+
132+
/**
133+
* @param {string} message
134+
* @returns {never}
135+
* @throws {Error}
136+
*/
137+
function supports_error(message) {
138+
throw new Error(
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.`
140+
);
141+
}

packages/adapter-cloudflare/test/apps/pages/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"dev": "vite dev",
77
"build": "vite build",
8-
"preview": "wrangler pages dev .svelte-kit/cloudflare --port 8787",
8+
"preview": "wrangler pages dev .svelte-kit/cloudflare --port 8787",
99
"prepare": "svelte-kit sync || echo ''",
1010
"test": "playwright test"
1111
},

packages/kit/src/exports/public.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ export interface Adapter {
3636
*/
3737
adapt: (builder: Builder) => MaybePromise<void>;
3838
/**
39-
* Checks called during dev and build to determine whether specific features will work in production with this adapter
39+
* Checks called during dev and build to determine whether specific features will work in production with this adapter.
4040
*/
4141
supports?: {
4242
/**
43-
* Test support for `read` from `$app/server`
44-
* @param config The merged route config
43+
* Test support for `read` from `$app/server`.
44+
* @param details.config The merged route config
4545
*/
4646
read?: (details: { config: any; route: { id: string } }) => boolean;
4747
};
4848
/**
4949
* Creates an `Emulator`, which allows the adapter to influence the environment
50-
* during dev, build and prerendering
50+
* during dev, build and prerendering.
5151
*/
5252
emulate?: () => MaybePromise<Emulator>;
5353
}
@@ -790,7 +790,7 @@ export type HandleClientError = (input: {
790790
}) => MaybePromise<void | App.Error>;
791791

792792
/**
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).
794794
*/
795795
export type HandleFetch = (input: {
796796
event: RequestEvent;
@@ -1409,7 +1409,7 @@ export interface ServerLoadEvent<
14091409
}
14101410

14111411
/**
1412-
* Shape of a form action method that is part of `export const actions = {..}` in `+page.server.js`.
1412+
* Shape of a form action method that is part of `export const actions = {...}` in `+page.server.js`.
14131413
* See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
14141414
*/
14151415
export type Action<
@@ -1419,7 +1419,7 @@ export type Action<
14191419
> = (event: RequestEvent<Params, RouteId>) => MaybePromise<OutputData>;
14201420

14211421
/**
1422-
* Shape of the `export const actions = {..}` object in `+page.server.js`.
1422+
* Shape of the `export const actions = {...}` object in `+page.server.js`.
14231423
* See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
14241424
*/
14251425
export type Actions<

packages/kit/src/exports/vite/preview/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { not_found } from '../utils.js';
1414
/** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */
1515

1616
/**
17-
* @param {{ middlewares: import('connect').Server }} vite
17+
* @param {import('vite').PreviewServer} vite
1818
* @param {import('vite').ResolvedConfig} vite_config
1919
* @param {import('types').ValidatedConfig} svelte_config
2020
*/

packages/kit/src/runtime/server/endpoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function render_endpoint(event, mod, state) {
1515

1616
let handler = mod[method] || mod.fallback;
1717

18-
if (method === 'HEAD' && mod.GET && !mod.HEAD) {
18+
if (method === 'HEAD' && !mod.HEAD && mod.GET) {
1919
handler = mod.GET;
2020
}
2121

packages/kit/types/index.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ declare module '@sveltejs/kit' {
1818
*/
1919
adapt: (builder: Builder) => MaybePromise<void>;
2020
/**
21-
* Checks called during dev and build to determine whether specific features will work in production with this adapter
21+
* Checks called during dev and build to determine whether specific features will work in production with this adapter.
2222
*/
2323
supports?: {
2424
/**
25-
* Test support for `read` from `$app/server`
26-
* @param config The merged route config
25+
* Test support for `read` from `$app/server`.
26+
* @param details.config The merged route config
2727
*/
2828
read?: (details: { config: any; route: { id: string } }) => boolean;
2929
};
3030
/**
3131
* Creates an `Emulator`, which allows the adapter to influence the environment
32-
* during dev, build and prerendering
32+
* during dev, build and prerendering.
3333
*/
3434
emulate?: () => MaybePromise<Emulator>;
3535
}
@@ -772,7 +772,7 @@ declare module '@sveltejs/kit' {
772772
}) => MaybePromise<void | App.Error>;
773773

774774
/**
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 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).
776776
*/
777777
export type HandleFetch = (input: {
778778
event: RequestEvent;
@@ -1391,7 +1391,7 @@ declare module '@sveltejs/kit' {
13911391
}
13921392

13931393
/**
1394-
* Shape of a form action method that is part of `export const actions = {..}` in `+page.server.js`.
1394+
* Shape of a form action method that is part of `export const actions = {...}` in `+page.server.js`.
13951395
* See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
13961396
*/
13971397
export type Action<
@@ -1401,7 +1401,7 @@ declare module '@sveltejs/kit' {
14011401
> = (event: RequestEvent<Params, RouteId>) => MaybePromise<OutputData>;
14021402

14031403
/**
1404-
* Shape of the `export const actions = {..}` object in `+page.server.js`.
1404+
* Shape of the `export const actions = {...}` object in `+page.server.js`.
14051405
* See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
14061406
*/
14071407
export type Actions<

0 commit comments

Comments
 (0)