invertase / dart_edge

Run Dart on the Edge - supporting Vercel & Cloudflare Workers (more coming soon).
https://docs.dartedge.dev
Apache License 2.0
318 stars 22 forks source link

How to fetch environment variables? #42

Open noga-dev opened 1 year ago

noga-dev commented 1 year ago
const testEnvVar = String.fromEnvironment(
    'SUPABASE_URL',
    defaultValue: 'defaultVal',
  );

The env var SUPABASE_URL comes built in as a default secret, per https://supabase.com/docs/guides/functions/secrets, yet defaultVal is returned.

henry2man commented 1 year ago

Secrets can be read using

Deno.env.get('VARIABLE_NAME')

Secrets must be managed by Supabase CLI with standard supabase secrets list/set commands. Secrets are written in environment files (DO NOT ADD THEM TO GIT, exclude them in .gitignore):

./supabase/.env (for PRODUCTION) ./supabase/.env.local (for local dev)

In order to make work local secrets during development, you need to add an extra --env-file file parameter to your serve command:

supabase functions serve dart_edge --no-verify-jwt --env-file ./supabase/.env.local

You can check this in the video https://youtu.be/53jhgrDONW4

Hope this helps

PS: Maybe we should add this to the README.md, isn't it?

noga-dev commented 1 year ago

Oh, I didn't realize I had access to Deno as an object inside main.dart. Thanks for this!

Works great and should definitely be added to the readme.

Leaving this issue open for the maintainers to address the docs/readme.