Skip to content

Implements redirects, headers for SSR#2798

Merged
matthewp merged 7 commits intomainfrom
ssr-redirect-2
Mar 16, 2022
Merged

Implements redirects, headers for SSR#2798
matthewp merged 7 commits intomainfrom
ssr-redirect-2

Conversation

@matthewp
Copy link
Copy Markdown
Contributor

Note that the API changes in this PR are behind the --experimental-ssr flag and are subject to change pending an RFC. These features should only be used for experimentation and not in a production setting.

See a demo of this PR here: https://www.loom.com/share/0e9831dbb2084b1bb1b13f75c10aa707

Changes

  • Adds support for the following APIs behind the experimental-ssr flag:
    • Astro.request is a Request object. This allows you to get the request.headers, to check if a user is logged in.
    • Frontmatter can return a Response, which allows you to return 404, or 301, etc. Fully power of HTTP inside of the frontmatter.
    • Astro.redirect is a convenience function for doing a redirect.
    • An API route can also return a Response. This is so it can set headers, etc.

Testing

  • SSR Example app is where testing is done in this PR. Unit tests to come as the APIs become more firm.

Docs

  • I have a separate ticket to document these changes.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 15, 2022

🦋 Changeset detected

Latest commit: 92ddffc

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

This PR includes changesets to release 1 package
Name Type
astro Patch

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 pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) labels Mar 15, 2022
@matthewp matthewp force-pushed the ssr-redirect-2 branch 3 times, most recently from 82751e4 to e9cffc7 Compare March 15, 2022 15:36
@matthewp matthewp marked this pull request as draft March 15, 2022 17:10
@natemoo-re
Copy link
Copy Markdown
Member

natemoo-re commented Mar 15, 2022

Not sure what happened with the changeset here. Changeset issue fixed by #2804

@matthewp matthewp marked this pull request as ready for review March 15, 2022 18:54
Copy link
Copy Markdown
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

This is looking great! I want to take another look at this before approving but the demo is super impressive.

Copy link
Copy Markdown
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

LGTM! I left some nit comments

Copy link
Copy Markdown
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

This is great! Approved. 🎉

@matthewp matthewp merged commit 4c25a1c into main Mar 16, 2022
@matthewp matthewp deleted the ssr-redirect-2 branch March 16, 2022 16:16
@github-actions github-actions bot mentioned this pull request Mar 16, 2022
@github-actions github-actions bot mentioned this pull request Mar 25, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* Implements redirects, headers for SSR

* Move away from an explicit Request

* Properly handle endpoint routes in the build

* chore(lint): ESLint fix

* Update based on review comments

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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) pkg: example Related to an example package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants