Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update save.js #108

Merged
merged 3 commits into from
Mar 2, 2022
Merged

Update save.js #108

merged 3 commits into from
Mar 2, 2022

Conversation

BliiTzZ
Copy link
Contributor

@BliiTzZ BliiTzZ commented Mar 2, 2022

A PR in SvelteKit introduces a number of breaking changes that

lay the foundation for streaming request/response bodies
enable multipart form handling (including file uploads)
better align SvelteKit with modern platforms that deal with Request and Response objects natively

Hooks (handle, handleError and getSession) and endpoints previously received a proprietary Request object:

interface Request<Locals = Record<string, any>, Body = unknown> {
  url: URL;
  method: string;
  headers: RequestHeaders;
  rawBody: RawBody;
  params: Record<string, string>;
  body: ParameterizedBody<Body>;
  locals: Locals;
}

Instead, they now receive a RequestEvent:

export interface RequestEvent<Locals = Record<string, any>> {
  request: Request; // https://developer.mozilla.org/en-US/docs/Web/API/Request
  url: URL; // https://developer.mozilla.org/en-US/docs/Web/API/URL
  params: Record<string, string>;
  locals: Locals;
}

method and headers are no longer necessary as they exist on the request object. (url is still provided, since the URL object contains conveniences like url.searchParams.get('foo'), whereas request.url is a string.)

To access the request body use the text/json/arrayBuffer/formData methods, e.g. body = await request.json().
See sveltejs/kit#3384 for details

A PR in SvelteKit introduces a number of breaking changes that

lay the foundation for streaming request/response bodies
enable multipart form handling (including file uploads)
better align SvelteKit with modern platforms that deal with `Request` and `Response` objects natively

Hooks (`handle`, `handleError` and `getSession`) and endpoints previously received a proprietary `Request` object:
```ts
interface Request<Locals = Record<string, any>, Body = unknown> {
  url: URL;
  method: string;
  headers: RequestHeaders;
  rawBody: RawBody;
  params: Record<string, string>;
  body: ParameterizedBody<Body>;
  locals: Locals;
}
```
Instead, they now receive a `RequestEvent`:

```ts
export interface RequestEvent<Locals = Record<string, any>> {
  request: Request; // https://developer.mozilla.org/en-US/docs/Web/API/Request
  url: URL; // https://developer.mozilla.org/en-US/docs/Web/API/URL
  params: Record<string, string>;
  locals: Locals;
}
```
`method` and `headers` are no longer necessary as they exist on the `request` object. (`url` is still provided, since the `URL` object contains conveniences like `url.searchParams.get('foo')`, whereas `request.url` is a string.)

To access the request body use the text/json/arrayBuffer/formData methods, e.g. `body = await request.json()`.
See sveltejs/kit#3384 for details
@vercel
Copy link

vercel bot commented Mar 2, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/sveltejs/realworld/2gSMVuGZJ6qaM971ggdPmV8DTkbw
✅ Preview: https://realworld-git-fork-bliitzz-patch-1-sveltejs1.vercel.app

src/routes/auth/save.js Outdated Show resolved Hide resolved
@benmccann
Copy link
Member

thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants