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

Binary endpoints not working with adapter-node #1873

Closed
mukaschultze opened this issue Jul 11, 2021 · 0 comments · Fixed by #1875
Closed

Binary endpoints not working with adapter-node #1873

mukaschultze opened this issue Jul 11, 2021 · 0 comments · Fixed by #1875

Comments

@mukaschultze
Copy link

Describe the bug

Endpoints that return an Uint8Array fail with the message

The "chunk" argument must be of type string or an instance of Buffer. Received an instance of Uint8Array

when using adapter-node.

To Reproduce
Use the following endpoint and try to access it on the browser using a build that runs with adapter-node:

import type { RequestHandler } from '@sveltejs/kit';

export const get: RequestHandler = async (request) => {
	const headers = {
		'content-type': 'application/octet-stream'
	};

	return {
		status: 200,
		headers,
		body: new Uint8Array([1,2,3,4,5])
	};
};

Expected behavior
The build should return the correct binary data in the same way as svelte-kit dev and svelte-kit preview.

Stacktraces
No stacktraces, but the issue is caused by

if (rendered) {
res.writeHead(rendered.status, rendered.headers);
res.end(rendered.body);
} else {
res.statusCode = 404;
res.end('Not found');
}

Information about your SvelteKit Installation:

Diagnostics

System:
OS: Windows 10 10.0.19043
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 9.53 GB / 31.80 GB
Binaries:
Node: 14.17.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 91.0.4472.124
Edge: Spartan (44.19041.1023.0), Chromium (91.0.864.67)
npmPackages:
@sveltejs/adapter-node: next => 1.0.0-next.32
@sveltejs/kit: next => 1.0.0-next.124
svelte: ^3.34.0 => 3.38.3

Additional context
Issue #1381 mentions this error, but it's closed and its PR is already merged.

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 a pull request may close this issue.

1 participant