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

quality of life updates for App #9579

Merged
merged 10 commits into from
Jan 8, 2024
Merged

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Jan 2, 2024

Why?

This came from working on 5 adapters over the past month. The logic for dealing with cookies and node:http is always duplicated. NodeApp takes care of converting the request, but the logic of converting response is duplicated across the node and the vercel adapters. Cookies had to be handled manually for legacy reasons (I think), but all adapters we maintain are now doing the same thing.

Changes

  • Exposes well-known symbols as a static property on App. (App.Symbol.locals, App.Symbol.clientAddress)
  • Adds helper functions for node-based runtimes to manage WHATWG Request and Response objects as static methods on NodeApp.
  • App.getSetCookieFromResponse() in favor of app.setCookieHeaders() (confusing name)
  • app.render(request, { addCookieHeader: true })

Testing

Tests for most of the functionality here are already present. This PR only exposes the APIs on App and NodeApp to prevent duplication across adapters.

Docs

Pending

Copy link

changeset-bot bot commented Jan 2, 2024

🦋 Changeset detected

Latest commit: abd6986

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 pkg: astro Related to the core `astro` package (scope) docs pr A PR that includes documentation for review labels Jan 2, 2024
@Princesseuh Princesseuh added this to the 4.2.0 milestone Jan 2, 2024
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Here's some preliminary feedback: since there isn't an issue nor an RFC where reviewers can understand the reasons and use cases of these additions, I suggest expanding the description of the PR, and telling us why these APIs were added, with possible use cases.

This will help us reviewers to have a better context and help you to land these new features.

.changeset/cool-foxes-talk.md Outdated Show resolved Hide resolved
.changeset/cool-foxes-talk.md Outdated Show resolved Hide resolved
@lilnasy
Copy link
Contributor Author

lilnasy commented Jan 3, 2024

Thanks, added a section to the description.

@ematipico
Copy link
Member

but the logic of converting response is duplicated across the node and the vercel adapters.

Could you add a couple of examples?

packages/astro/src/core/app/index.ts Outdated Show resolved Hide resolved
packages/astro/src/core/app/index.ts Show resolved Hide resolved
packages/astro/src/core/app/node.ts Outdated Show resolved Hide resolved
packages/astro/src/core/app/node.ts Outdated Show resolved Hide resolved
packages/astro/src/core/app/node.ts Outdated Show resolved Hide resolved
@lilnasy lilnasy changed the base branch from main to adapter-enhancements January 4, 2024 16:25
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

I would like to see some tests to make sure that the new APIs behave as expected. We can add these tests in a separate PR if you want, but I think it's best to have them there, together with the new logic.

We have a test adapter, we can use that one to run some cases

@lilnasy
Copy link
Contributor Author

lilnasy commented Jan 5, 2024

Yeah, that makes sense.

@github-actions github-actions bot added pkg: solid Related to Solid (scope) pkg: integration Related to any renderer integration (scope) labels Jan 5, 2024
@github-actions github-actions bot removed pkg: solid Related to Solid (scope) pkg: integration Related to any renderer integration (scope) labels Jan 8, 2024
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Looks good to me, let's merge it and move to the next one :)

@ematipico
Copy link
Member

@lilnasy I rebased this PR and the adapter-enhancements branch

@lilnasy
Copy link
Contributor Author

lilnasy commented Jan 8, 2024

Thanks for the rebase!

@lilnasy lilnasy merged commit 10b2541 into withastro:adapter-enhancements Jan 8, 2024
13 checks passed
@lilnasy lilnasy deleted the app branch January 8, 2024 13:57
ematipico added a commit that referenced this pull request Jan 17, 2024
* quality of life updates for `App` (#9579)

* feat(app): writeResponse for node-based adapters

* add changeset

* Apply suggestions from code review

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* Apply suggestions from code review

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* add examples for NodeApp static methods

* unexpose createOutgoingHttpHeaders from public api

* move headers test to core

* clientAddress test

* cookies test

* destructure renderOptions right at the start

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* Fallback node standalone to localhost (#9545)

* Fallback node standalone to localhost

* Update .changeset/tame-squids-film.md

* quality of life updates for the node adapter (#9582)

* descriptive names for files and functions

* update tests

* add changeset

* appease linter

* Apply suggestions from code review

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>

* `server-entrypoint.js` -> `server.js`

* prevent crash on stream error (from PR 9533)

* Apply suggestions from code review

Co-authored-by: Luiz Ferraz <luiz@lferraz.com>

* `127.0.0.1` -> `localhost`

* add changeset for fryuni's fix

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

---------

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Co-authored-by: Luiz Ferraz <luiz@lferraz.com>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* chore(vercel): delete request response conversion logic (#9583)

* refactor

* add changeset

* bump peer dependencies

* unexpose symbols (#9683)

* Update .changeset/tame-squids-film.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

---------

Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com>
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Co-authored-by: Luiz Ferraz <luiz@lferraz.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr A PR that includes documentation for review pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants