Possible to hit localhost from database functions and/or Edge functions? #9837
Replies: 10 comments 23 replies
-
Hi @drewbietron, you can connect to localhost from within the db container using ip address create trigger index_products_to_search
after insert or update or delete on products
for each row execute procedure
public.send_to_webhook( 'http://172.17.0.1:54321/functions/v1/function-name' ); I haven't tested this trigger per se, so let me know if it works. |
Beta Was this translation helpful? Give feedback.
-
This should really be mentioned somewhere in the docs. It took me way too long to track this down |
Beta Was this translation helpful? Give feedback.
-
Is there any easy way right now? |
Beta Was this translation helpful? Give feedback.
-
Hi, I am in macos and I am still not able to call my local nestjs api serveur (running on 3000) from a database trigger. In the net._http_response I still got Is there another way to hit my local api from the supabase cli database ? |
Beta Was this translation helpful? Give feedback.
-
Created following snippet that creates trigger to call edge function endpoint based on environment.
Pros:
Cons:
I use the snippet in following development workflow when I want to trigger edge function on database event. In bot local development and production.
I didn’t fully test this with supabase migration as I use drizzle. But I am pretty sure this works as stated. Edit: Better IP check and instread localhost it uses |
Beta Was this translation helpful? Give feedback.
-
For those that don't want to use a hardcoded ip like Ex:
|
Beta Was this translation helpful? Give feedback.
-
Did anyone find a way to achieve this using Linux? |
Beta Was this translation helpful? Give feedback.
-
It took me so long to find this answer and thank god for the thread there's no way I would have thought to check Docker. It should be emitted as part of
|
Beta Was this translation helpful? Give feedback.
-
for local host from edge functions you can use e.g.
|
Beta Was this translation helpful? Give feedback.
-
If someone is struggling with "Couldn't connect to server" or "Timeout was reached" on self-host docker supabase, you can try to use that URL for your webhook |
Beta Was this translation helpful? Give feedback.
-
I am trying to stick to a fully local development setup (locally) and am having troubles making requests to localhost from both a postgres function, or from an Edge Function. I know that both are ran via the Docker setup from the Supabase CLI, but I've tried about every combination of things I can try in order to make requests to localhost.
I've realized that localhost from the context of a Docker container, is just that container, not the machine's localhost. As an attempted work around for this, I've tried hitting the exposed Docker IP (in my case
172.25.145.178
) in the database functions and/or Edge functions, but that doesn't work. I've also added a URL to my hosts config locally so that the IP above can accept requests at a URL vs an IP (egapp.local -> 172.25.145.178
) which exposes my Nextjs web app and search service to their corresponding ports at app.local, but that doesn't work in the database either.I plan on storing the url's using Supabase Vault secrets, which will allow me to have different values for different Supabase environments (eg localhost:3000, staging.app.com, production.app.com etc) and reference those variables within my functions or Edge Functions. I just can't seem to get it wired up to my locally ran services. Any help would be appreciated.
Here's some example database functions
Tried localhost, that doesnt work since these services aren't ran from within the Supabase local Docker container
Tried adding a recoerd to hosts to listen at a URL vs localhost but no luck
Would also use the same approach to hit a locally served Edge function. This one I thought might actually work since this localhost is part of the running Docker container, but no luck.
Any help would be appreciated. Getting this nailed down would really help me get a great local dev setup going!
Beta Was this translation helpful? Give feedback.
All reactions