postgresqldockernext.jsdockerfilefly

fly.io: next.js build fails on prerendering route with postgres


I'm just starting with fly.io. My environment:

When I do fly deploy I receive this:

Generating static pages (0/7) ...
12.16 
12.16 Error occurred prerendering page "/api/my-api-route". Read more: https://nextjs.org/docs/messages/prerender-error
12.16 
12.16 AggregateError [ECONNREFUSED]: 
12.16     at internalConnectMultiple (node:net:1114:18)
12.16     at afterConnectMultiple (node:net:1667:5)
12.16     at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)

Which points to the postgres not connecting to the DATABASE_URL.

I tried:

I don't think it should take that much time to deploy a simple next.js app, so I feel like I am missing something obvious.


Solution

  • Turns out I was able to send DATABASE_URL before, but npm run build from within the Docker cannot connect to the postgres app, localhost:5432 (specifics of Fly.io, you can either have a paid-for IP4 and use that, or you have to use proxy to connect to postgres app).

    I was able to connect using host “<app-name>.internal:5432”.