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

refactor: remove endpoint handling infra #9775

Merged
merged 2 commits into from
Jan 23, 2024

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Jan 22, 2024

Changes

  • When an endpoint that matches the path does not export the request method. a reroute to 404.astro is performed.
  • This was done using "endpointHandler" on Pipeline implemented once for each environment. callEndpoint created a response with a special header. The endpoint handler recognises the special header and throws a special error. Then App recognises the special error and finally performs the rerouting.
  • Now, callEndpoint creates a response with a special header ("X-Astro-Reroute=no"), and App recognises it to perform the rerouting directly.
  • The meaning of the special header is reversed. Previously, it opted certain endpoint responses into rerouting (after endpoints were blanket opted-out). Now, endpoints get no blanket treatment, and the header opts-out individual responses.
  • The overarching rerouting behavior will be extracted out into an internal middleware soon.

Testing

Does not affect behavior. Existing tests should pass.

Docs

Does not affect usage.

Copy link

changeset-bot bot commented Jan 22, 2024

🦋 Changeset detected

Latest commit: c1c91fa

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 Jan 22, 2024
Copy link
Member

Choose a reason for hiding this comment

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

Refactors should not have changelogs, since users don't need to know about these refactors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went back and forth on this. We can't say ever say for sure, there won't be regression and the changelog comes in handy. At the end, it's just another entry in the changelog.

});
}
if (REROUTABLE_STATUS_CODES.has(response.status) && response.headers.get("X-Astro-Reroute") !== "no") {
return this.#renderError(request, {
Copy link
Member

Choose a reason for hiding this comment

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

Why did we remove the routeData.type === 'page' || routeData.type === 'redirect' check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was there to carve out endpoints from the rerouting behavior. That does not happen anymore.

const response = await handler.call(mod, context);
// Endpoints explicitly returning 404 or 500 response status should
// NOT be subject to rerouting to 404.astro or 500.astro.
response.headers.set("X-Astro-Reroute", "no");
Copy link
Member

Choose a reason for hiding this comment

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

We might as well move X-Astro-Reroute to a const at this point, to avoid possible typos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea. I can do that in a future PR.

@lilnasy lilnasy merged commit 075706f into withastro:main Jan 23, 2024
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Jan 23, 2024
@lilnasy lilnasy deleted the refactor-endpoint-handler branch January 23, 2024 14:17
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.

3 participants