S
Supabase•7mo ago
kliuksas

Edge function, custom domain and `SUPABASE_URL` env variable

hello 👋 after setting up custom domain, i can call my edge function via that custom domain, but SUPABASE_URL env variable is pointing to the original URL and not to the custom domain. i'm unable to change SUPABASE_URL env variable, due to error:
$ supabase secrets set SUPABASE_URL="https://api.my-new-domain.com"
Env name cannot start with SUPABASE_, skipping: SUPABASE_URL
Try rerunning the command with --debug to troubleshoot the error.
$ supabase secrets set SUPABASE_URL="https://api.my-new-domain.com"
Env name cannot start with SUPABASE_, skipping: SUPABASE_URL
Try rerunning the command with --debug to troubleshoot the error.
I'm using edge function to upload files to supabase storage and respond with the uploaded URL with:
const url = supabase.storage.from('my-bucket-name').getPublicUrl('my-file').data.publicUrl
const url = supabase.storage.from('my-bucket-name').getPublicUrl('my-file').data.publicUrl
the url is pointing to https://abcdefgh.supabase.co/storage... instead of https://api.my-new-domain.com/storage.... i can fix this on my own by replacing the domain, still would be nice to avoid such juggling. also posted on GH discussion: https://github.com/orgs/supabase/discussions/13371#discussioncomment-9469267
4 Replies
silentworks
silentworks•7mo ago
You cannot set any SUPABASE_ prefixed env variables as they are setup by default https://supabase.com/docs/guides/functions/secrets#default-secrets.
kliuksas
kliuksasOP•7mo ago
thanks for reply! yes, i realize that from the error message. does it mean, SUPABASE_URL in edge function is always hard-set to the original supabase project URL (the one before setting up custom domain)? if that's correct, then i'll do a publicFileUrl.replace(Deno.env.get('SUPABASE_URL'), 'https://api.my-new-domain.com'). i was assuming that SUPABASE_URL env var automatically points to custom domain once that gets set up.
silentworks
silentworks•7mo ago
I don't see anything in the docs explaining what it should be when using custom domains. I personally don't use custom domains. Maybe open an issue on the edge-runtime Github repo to see what those working on the code says it should be.
i was assuming that SUPABASE_URL env var automatically points to custom domain once that gets set up.
From reading the custom domain docs I would have thought this too.
kliuksas
kliuksasOP•7mo ago
for future searchers: in the end i'm just manually replacing SUPABASE_URL with my custom domain:
const fileUrl =
supabase.storage.from('my-bucket-name').getPublicUrl('some-path').data.publicUrl;

const newDomainUrl = fileUrl.replace(
Deno.env.get("SUPABASE_URL"),
"https://api.my-custom-domain.com",
);
const fileUrl =
supabase.storage.from('my-bucket-name').getPublicUrl('some-path').data.publicUrl;

const newDomainUrl = fileUrl.replace(
Deno.env.get("SUPABASE_URL"),
"https://api.my-custom-domain.com",
);

Did you find this page helpful?