S
Supabase2mo ago
loup

How access env variable in edge function (self hosted) ?

Well I guess we are supposed to add .env in /functions/.env but even doing it, env var only contain :
SB_EXECUTION_ID: ...,
HOSTNAME: ...,
JWT_SECRET: ...,
SUPABASE_URL: ...,
PATH: ...,
SUPABASE_SERVICE_ROLE_KEY: ...,
SUPABASE_DB_URL: ...,
SUPABASE_ANON_KEY: ...,
HOME: "/root",
VERIFY_JWT: "false"
SB_EXECUTION_ID: ...,
HOSTNAME: ...,
JWT_SECRET: ...,
SUPABASE_URL: ...,
PATH: ...,
SUPABASE_SERVICE_ROLE_KEY: ...,
SUPABASE_DB_URL: ...,
SUPABASE_ANON_KEY: ...,
HOME: "/root",
VERIFY_JWT: "false"
But adding a custom one in .env file isnt working... What do I miss ?
2 Replies
loup
loupOP2mo ago
In my VPS I have :
ls -a volumes/functions/ .env .env.template hello main revenue-cat
ls -a volumes/functions/ .env .env.template hello main revenue-cat
So there is my .env Okay I found, well the doc is kinda broken for this, but we have to add env_file inside the docker compose :
functions:
container_name: supabase-edge-functions
image: supabase/edge-runtime:v1.69.6
restart: unless-stopped
volumes:
- ./volumes/functions:/home/deno/functions:Z
depends_on:
analytics:
condition: service_healthy
env_file:
- ./volumes/functions/.env # <====== HERE ADD THE PATH OF THE ENV FILE TO ADD EXTRA ENV
environment:
JWT_SECRET: ${JWT_SECRET}
SUPABASE_URL: http://kong:8000
SUPABASE_ANON_KEY: ${ANON_KEY}
SUPABASE_SERVICE_ROLE_KEY: ${SERVICE_ROLE_KEY}
SUPABASE_DB_URL: postgresql://postgres:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
# TODO: Allow configuring VERIFY_JWT per function. This PR might help: https://github.com/supabase/cli/pull/786
VERIFY_JWT: "${FUNCTIONS_VERIFY_JWT}"
functions:
container_name: supabase-edge-functions
image: supabase/edge-runtime:v1.69.6
restart: unless-stopped
volumes:
- ./volumes/functions:/home/deno/functions:Z
depends_on:
analytics:
condition: service_healthy
env_file:
- ./volumes/functions/.env # <====== HERE ADD THE PATH OF THE ENV FILE TO ADD EXTRA ENV
environment:
JWT_SECRET: ${JWT_SECRET}
SUPABASE_URL: http://kong:8000
SUPABASE_ANON_KEY: ${ANON_KEY}
SUPABASE_SERVICE_ROLE_KEY: ${SERVICE_ROLE_KEY}
SUPABASE_DB_URL: postgresql://postgres:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
# TODO: Allow configuring VERIFY_JWT per function. This PR might help: https://github.com/supabase/cli/pull/786
VERIFY_JWT: "${FUNCTIONS_VERIFY_JWT}"
Kalleby Santos
Kalleby Santos2mo ago
Hi @loup For self-hosted projects the Enviroment variables are injected to workers from Main. Like you can see on this line by default it will get the currently container environments and foward it to workers. But you can extend it with your own custom logic, like search for the .env file at same way it already search for the "service_path", then you can extend the envVars object with the contents of the found local .env file. This way you don't need to manually include it into your docker-compose

Did you find this page helpful?