-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
docs(endpoints): added new example for returning buffers from endpoints #3154
Conversation
When using the encoding: 'binary' providers like vercel send the buffer as plain text instead of a binary png. This can be prevented by using the Response object (just like in other frameworks like svelte)
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing this! I followed your and @Princesseuh's conversation trail, and I tried to make the note more direct.
Erika, can you please fact-check this? And, I know you mentioned something about adding documentation about this. Would you consider this note sufficient, or do you think we should consider replacing the existing example with one that returns a Response
? Is that something that will work in all situations, so is maybe more universal to show?
@@ -40,6 +40,18 @@ export async function get({ params, request }) { | |||
} | |||
``` | |||
|
|||
This method of returning a buffer as a response might not work for certain providers like vercel because the `Content-Type` header cannot be specified. For returning images prefer the following way (i.e. return a `Response`-Object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method of returning a buffer as a response might not work for certain providers like vercel because the `Content-Type` header cannot be specified. For returning images prefer the following way (i.e. return a `Response`-Object): | |
Certain providers require the `Content-Type` header to return an image. In this case, return a `Response` object instead which allows you to specify a `headers` property. | |
For example, to produce a `.png` image on Vercel: |
In my opinion the example I added should be the default way to return Buffers in general. Maybe we should replace the 'binary' example completely (as it doesn't work). Making this work has cost me days and this could be a huge deterrent for anyone that tries to use s3 buckets or any other form of buffered images. |
I'm going to ask @delucis what he thinks about this! |
Thanks for your patience on this this @haasal! Looking at the original I believe the current example is for static scenarios (where Astro needs to write the endpoint to the filesystem while building). I’m not sure if we actually support returning |
Yes. Now I see it too. However it mentions nowhere in the docs how to do it with SSR on, which is really important (I.e. s3 buckets). So I would simply add my paragraph/example slightly modified to the SSR part of the endpoint guide |
@haasal Would you be willing to update this PR to modify the paragraph and example slightly, as you suggested, and move it to the SSR section? |
Sure. I'll add the example to the SSR section. |
Hi @haasal - Just checking in here to see whether you're still up for this! I'm sorry, I've been so swamped getting next weeks' big launch docs together for our new features, I've been a little slow to follow up on community PRs. But we would be so happy to have your contribution, if you're still interested! |
… endpoints" This reverts commit d0f6509.
I think this should be ready. I messed up something with git along the way. Please check if everything is correct before merging. |
What kind of changes does this PR include?
New content/code-snippet in the docs
Description
The PR adresses this closed issue.
When using the encoding: 'binary' providers like vercel send the buffer as plain text instead of a binary png. This can be prevented by using the Response object (just like in other frameworks like svelte)