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: extended cloudflare context #677

Closed
wants to merge 4 commits into from
Closed

feat: extended cloudflare context #677

wants to merge 4 commits into from

Conversation

barisbora
Copy link

πŸ”— Linked issue

resolves #391

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Extending context object with cloudflare CF Properties and headers

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@barisbora barisbora changed the title Feat/cloudflare context feat: extended cloudflare context Nov 20, 2022
function toNodeListener (app: App, context: H3EventContext): NodeListener {
const toNodeHandle: NodeListener = async function (req, res) {
const event = createEvent(req, res)
event.context = { ...event.context, ...context }
Copy link
Member

Choose a reason for hiding this comment

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

I think we might want to add CF context as event.context.cloudflare for better type support.

Copy link
Contributor

@timhanlon timhanlon Jan 19, 2023

Choose a reason for hiding this comment

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

Suggested change
event.context = { ...event.context, ...context }
event.context = { ...event.context, cloudflare: context }

Copy link
Member

Choose a reason for hiding this comment

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

Oops - didn't mean to edit. What about?

Suggested change
event.context = { ...event.context, ...context }
event.context.cloudflare = context

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for feedback, implemented πŸ™Œ

@codecov
Copy link

codecov bot commented Nov 21, 2022

Codecov Report

Merging #677 (f62e761) into main (574f74e) will not change coverage.
The diff coverage is n/a.

❗ Current head f62e761 differs from pull request most recent head c9ba349. Consider uploading reports for the commit c9ba349 to get more accurate results

@@           Coverage Diff           @@
##             main     #677   +/-   ##
=======================================
  Coverage   66.91%   66.91%           
=======================================
  Files          57       57           
  Lines        4232     4232           
  Branches      459      460    +1     
=======================================
  Hits         2832     2832           
  Misses       1397     1397           
  Partials        3        3           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

function toNodeListener (app: App, context: H3EventContext): NodeListener {
const toNodeHandle: NodeListener = async function (req, res) {
const event = createEvent(req, res)
event.context.cloudflare = context
Copy link
Member

Choose a reason for hiding this comment

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

Should this be:

Suggested change
event.context.cloudflare = context
event.context.cloudflare = context.cf

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the answer to this depends on where you'll want the fetch event context to live when module syntax support lands in #681.

@pi0 pi0 mentioned this pull request Feb 8, 2023
7 tasks
@pi0
Copy link
Member

pi0 commented Feb 8, 2023

Thanks for working on this @barisbora ❀️ Adding support with a slightly more generic approach in #927

@pi0 pi0 closed this in #927 Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cloudflare request.cf
4 participants