Closed davidbogue closed 2 years ago
Using the latest versions of SvelteKit and the Adapters, the request object in POST APIs does not successfully extract the request body.
While debugging I noticed the request.body is not an object with the form fields, but is instead a Readable stream.
For example the existing register.js POST api returns an error that email is missing as it is written now:
export async function post({ request }) { const user = request.body;
The code works if it is changed to read the stream and parse the JSON into an object:
export async function post({ request }) { const user = JSON.parse(request.body.read());
I had the same issue in a personal project with recent SvelteKit changes, so the issue may actually be in SvelteKit.
This occurs with the latest realworld code: "node_modules/@sveltejs/kit": "version": "1.0.0-next.240" "@sveltejs/adapter-netlify": "version": "1.0.0-next.42" "@sveltejs/adapter-vercel": "version": "1.0.0-next.39"
fixed here: https://github.com/sveltejs/realworld/commit/9204725d05b04c18ce4f0d54c2c75b5bb6e0472b
Using the latest versions of SvelteKit and the Adapters, the request object in POST APIs does not successfully extract the request body.
While debugging I noticed the request.body is not an object with the form fields, but is instead a Readable stream.
For example the existing register.js POST api returns an error that email is missing as it is written now:
The code works if it is changed to read the stream and parse the JSON into an object:
I had the same issue in a personal project with recent SvelteKit changes, so the issue may actually be in SvelteKit.
This occurs with the latest realworld code: "node_modules/@sveltejs/kit": "version": "1.0.0-next.240" "@sveltejs/adapter-netlify": "version": "1.0.0-next.42" "@sveltejs/adapter-vercel": "version": "1.0.0-next.39"