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

feat(@astrojs/cloudfalre): add cloudflare envs to Astro.locals #7541

Merged
merged 23 commits into from
Aug 10, 2023
Merged

feat(@astrojs/cloudfalre): add cloudflare envs to Astro.locals #7541

merged 23 commits into from
Aug 10, 2023

Conversation

alexanderniebuhr
Copy link
Member

@alexanderniebuhr alexanderniebuhr commented Jun 30, 2023

Changes

Testing

  • manually tested with Cloudflare Pages Deployments.
  • duplicated integration test, which was used for getRuntime

Docs

/cc @withastro/maintainers-docs for feedback!

Notes:

  • It does not export a type yet. Users have to type the locals themself.

@changeset-bot
Copy link

changeset-bot bot commented Jun 30, 2023

🦋 Changeset detected

Latest commit: 45a52b2

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: integration Related to any renderer integration (scope) label Jun 30, 2023
@matthewp
Copy link
Contributor

Hey @alexanderniebuhr 👋 this is looking good, but is still in draft. Are you ready for people to review it?

@alexanderniebuhr
Copy link
Member Author

alexanderniebuhr commented Jul 14, 2023

Are you ready for people to review it?

@matthewp soon! Need to fix some types and double check a test! And it still needs docs! Will ping you here & in Discord :)

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 29, 2023
@alexanderniebuhr alexanderniebuhr marked this pull request as ready for review July 29, 2023 05:04
@alexanderniebuhr alexanderniebuhr requested a review from a team as a code owner July 29, 2023 05:04
@alexanderniebuhr
Copy link
Member Author

@matthewp I'm ready to get initial reviews :)

@alexanderniebuhr alexanderniebuhr changed the title feat(@astrojs/cloudfalre): add cloudflare envs as Astro.locals.env feat(@astrojs/cloudfalre): add cloudflare envs to Astro.locals Jul 29, 2023
packages/astro/src/core/endpoint/index.ts Outdated Show resolved Hide resolved
packages/astro/src/core/errors/errors-data.ts Outdated Show resolved Hide resolved
packages/integrations/cloudflare/src/server.directory.ts Outdated Show resolved Hide resolved
packages/integrations/cloudflare/src/server.directory.ts Outdated Show resolved Hide resolved
packages/integrations/cloudflare/src/server.directory.ts Outdated Show resolved Hide resolved
packages/integrations/cloudflare/src/server.directory.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the pkg: astro Related to the core `astro` package (scope) label Jul 31, 2023
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.

It would be great if we can add some tests, where we have a middleware.

Inside the middleware, should do something like:

  • context.locals.user.name = "Nick" -> no errors, it should work
  • context.locals.runtime = {} -> runtime error, can't override
  • context.locals = {}, allowed.. no runtime errors but log a warning to the user that wiping out locals is unsafe

packages/integrations/cloudflare/src/server.advanced.ts Outdated Show resolved Hide resolved
packages/integrations/cloudflare/src/server.advanced.ts Outdated Show resolved Hide resolved
packages/integrations/cloudflare/src/server.advanced.ts Outdated Show resolved Hide resolved
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Docs approves the changeset and README! 🥳

@lilnasy
Copy link
Contributor

lilnasy commented Aug 8, 2023

Would Astro.locals in the frontmatter have identical functionality to context.locals in the middleware?

For context, trying to decide on a different API for #7975, and this PR seems related.

@alexanderniebuhr
Copy link
Member Author

Would Astro.locals in the frontmatter have identical functionality to context.locals in the middleware?

AFAIK, no. This just passes the cf runtime to locals using the app.render() function.

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.

Almost there! I think we're good. Just one more thing: could you add a TODO comment to the getRuntime function as a reminder to remove it in the next major release of the library??

@lilnasy
Copy link
Contributor

lilnasy commented Aug 9, 2023

I would like there to be a convention for adapters introducing runtime controls through locals.

For #7975, I went with Astro.locals.netlify.setBuildersTtl() because I wanted it to be immediately clear that you might need to revisit it if you switch providers. But, I am not opposed to Astro.locals.runtime.setBuildersTtl().

What I consider important is that there is consistency.

@alexanderniebuhr
Copy link
Member Author

I would like there to be a convention for adapters introducing runtime controls through locals.

I am also fine with both. However I think this needs some RFC to align across everything. I really want this PR to get merged soon, so not sure if we can wait for the RFC. Any opinions cc @ematipico @matthewp

  • Astro.locals.<PROVIDER>.<XYZ>
  • Astro.locals.runtime.<XYZ>

@matthewp
Copy link
Contributor

lgtm! No opinion on namespacing from me, integrations can essentially do what they want here, I don't think an RFC is valid for this sort of thing. Adapters can coordinate if they'd like / think it makes things easier. I'm not sure if it does though, but that's my opinion.

Copy link
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.

Looks great!

One request from me: could we mark the getRuntime export as /** @deprecated */ so that users get this feedback in their IDE?

.changeset/fuzzy-jobs-explain.md Outdated Show resolved Hide resolved
@lilnasy
Copy link
Contributor

lilnasy commented Aug 10, 2023

In that case, I'll go with locals.runtime because I'd only have to change one line.

@natemoo-re natemoo-re merged commit ffcfcdd into withastro:main Aug 10, 2023
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Aug 10, 2023
@alexanderniebuhr alexanderniebuhr deleted the alexanderniebuhr/7538-astro-locals-cloudflare-env branch September 23, 2023 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[astrojs/cloudflare] use Astro.locals for env variable
6 participants