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

Allow 200 response for endpoints in build #5258

Merged
merged 1 commit into from
Oct 31, 2022
Merged

Allow 200 response for endpoints in build #5258

merged 1 commit into from
Oct 31, 2022

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Oct 31, 2022

Changes

Fix #4930

  • Allow returning response with 200 status code from static endpoints.
  • Throw on 300 status code for static endpoints like in dev mode.
  • Also throw on 300 status code for page endpoints on build, previously would silently skip.

These changes should make build similar to dev.

Testing

I'm not sure how to test errors that would cause build to fail, but I did test with #4930 to make sure it works.

Docs

Currently the docs doesn't document that they can return a response for static endpoints. I'll document this separately but I don't think it blocks this PR.

withastro/docs#1961

@changeset-bot
Copy link

changeset-bot bot commented Oct 31, 2022

🦋 Changeset detected

Latest commit: 512d5bf

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Oct 31, 2022
@bluwy bluwy merged commit 74759cf into main Oct 31, 2022
@bluwy bluwy deleted the endpoint-200-build branch October 31, 2022 16:58
@astrobot-houston astrobot-houston mentioned this pull request Oct 31, 2022
yongzhenlow added a commit to yongzhenlow/yzlow that referenced this pull request Nov 5, 2022
throwIfRedirectNotAllowed(result.response, opts.settings.config);
// If there's no body, do nothing
if (!result.response.body) return;
body = await result.response.text();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be something like body = await result.response.arrayBuffer().then(ab => new Uint8Array(ab)).

Not all response bodies, e.g. images, are valid UTF-8 strings so using Response.text() returns unexpected data during build.

Example: returning new Response(new Uint8Array([0xff])) from a static file endpoint causes Astro (v1.8.0; Node v18.11.0) to generate a file containing <ef bf bd> instead of <ff>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bmdelacruz! In general it’s safest to create a new issue if you’re seeing buggy behaviour as sometimes older issues and PRs aren’t picked up in the triage process. Would you be able to do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Returning a Response from an API Route in SSG mode does not warn during development
4 participants