pg_net: Can't send HTTP requests to localhost from a trigger function
Bug report
Describe the bug
When trying to send a request from a trigger function, the request doesn’t reach the server. In the _http_response table, the error message is:
Couldn’t connect to server
To Reproduce
Do the following locally:
- Create an edge function, and serve it.
- Create a trigger function that makes an HTTP request to your edge function:
begin
perform
net.http_post(
url:='url_to_your_localhost_edge_function',
body:='{}'::jsonb
) as request_id;
return new;
end;
- Create a trigger that will execute the function
- Trigger the function
- You will notice the request did not reach the edge function.
Expected behavior
The request should go through.
Additional context
- I tried to use both 54321 and 8000 ports
- When I
curlmy edge function, it works - When I use an external URL instead of localhost, it works
System information
- OS: macOS
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (2 by maintainers)
Yep, this is unfortunately due to
localhostmapping to the Postgres container itself - to reach the Docker host (and all ports exposed on it), eitherhost.docker.internalor172.17.0.1have to be used as the target hostname.@HTMHell could you try using any of the above options to confirm that the http request connects as expected?
Is anyone still seeing this problem in 2024?
To be clear, we are directly inputting the
host.docker.internalbase URL into the supabase dashboard (local instance) right?