-
Notifications
You must be signed in to change notification settings - Fork 21
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
[Feature request] Automatically stringify JSON #80
Comments
@mpetrunic If there's interest, I can make a PR for this. |
Maybe you can first propose approach here (without breaking changes)? :) |
Simple : Thanks |
Ah I see, stringify data if it's an object. Yeah, I'm happy to accept PR with the changes. |
Oh wow, I completely missed this issue. I'll have a look around tomorrow and get to it if nobody else started the PR. |
In some cases, |
SSE common scenarios involve high-frequency requests. We need to reduce consumption. |
Yeah, I was just making an example, in practice I guess the library that Fastify currently uses for serializing JSON should be used here. |
just use JSON.stringify, we can edit this file. https://github.com/mpetrunic/fastify-sse-v2/blob/master/src/sse.ts export function isObject(value: any) {
return typeof value === 'object' && value !== null;
}
...
if (chunk.data) {
if (isObject(chunk.data)) {
payload += `data: ${JSON.stringify(chunk.data)}\n`;
} else {
payload += `data: ${chunk.data}\n`;
}
} |
Thanks
The text was updated successfully, but these errors were encountered: