Skip to content

Conversation

@nnelgxorz
Copy link
Contributor

@nnelgxorz nnelgxorz commented Aug 15, 2022

What is it?

  • Feature / enhancement
  • Bug
  • Docs / tests

Description

Adds the Cloudflare env parameter as an envData render option. Allows users to access Cloudflare env variables in their Qwik City code.

import { useEnvData, component$ } from '@builder.io/qwik';

export default component$(() => {
  const secret_password = useEnvData('secret');
  //....
});

Discussion here: #1066

Checklist:

  • My code follows the developer guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • Added new tests to cover the fix / functionality

@nnelgxorz nnelgxorz changed the title Add env param to Cloudlflare Middleware feat: Add env param to Cloudlflare Middleware Aug 15, 2022
@nnelgxorz nnelgxorz changed the title feat: Add env param to Cloudlflare Middleware feat: Add env param to Cloudflare Middleware Aug 16, 2022
@youngboy
Copy link
Contributor

youngboy commented Aug 16, 2022

this is great, while I think it is a common pattern that user able to access middleware request's context. other framework like svelte exposed a property platform attach to specific adapter context.

  1. for netlify, context have a useful util log and more in context, see https://docs.netlify.com/netlify-labs/experimental-features/edge-functions/api/#netlify-specific-context-object
  2. this suggesting useEnvData is common way get runtime's ENV, user might be frustrating if it is not work for the middleware he is using if not implemented.

@nnelgxorz
Copy link
Contributor Author

I agree @youngboy. What are your thoughts on improving this and making implementing it for Netlify and others?

@youngboy
Copy link
Contributor

youngboy commented Aug 16, 2022

I agree @youngboy. What are your thoughts on improving this and making implementing it for Netlify and others?

maybe something like this ?

export const onGet: RequestHandler = ({ platform }) => {
   platform.context.log('netlify logging')
  // or in CF, platform.context.env('my-env')
};

@elxris
Copy link

elxris commented Aug 16, 2022

@nnelgxorz I think this is a great and necessary feature but don't actually close the ticket I opened.

A PR that would actually close it would be to include the env context to the on___ request context.

@nnelgxorz
Copy link
Contributor Author

@elxris I removed the closes tag from my PR. Going off of @youngboy's suggestion, here's a second WIP PR.

#1072

@nnelgxorz
Copy link
Contributor Author

Closing in favor of #1072

@nnelgxorz nnelgxorz closed this Aug 22, 2022
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.

3 participants