a month ago
I have a weird deployment-related issue in my app. Here's what happens. My next.js app built with v0 deploys automatically on Vercel. Functionality is full, authentication works, communication with the database works. It has a Supabase database that handles authentication.
Now I'm trying to deploy the same app on my own Railway. It deploys, builds and starts there correctly. But then, It doesn't seem to be able to connect to Supabase database.
Some of the key differences between the setups :
Vercel app builds next.js app directly, while Railway solution uses docker to build it.
I'm using a free tier Supabase and a Pro tier Railway.
Here is some of the info from my app's logs on Railway :
[2025-03-28T16:40:13.286Z] [DEBUG] Storage getItem called in server context: supabase-auth
[2025-03-28T16:40:13.286Z] [DEBUG] Session check: No session
[2025-03-28T16:40:15.721Z] [DEBUG] Middleware processing: /login
[2025-03-28T16:40:19.651Z] [DEBUG] Storage getItem called in server context: supabase-auth
[2025-03-28T16:42:12.536Z] [DEBUG] Middleware processing: /api/health
[2025-03-28T16:42:12.542Z] [DEBUG] Health check endpoint called
[2025-03-28T16:42:12.543Z] [DEBUG] Environment variables check: {
NEXT_PUBLIC_SUPABASE_URL: true,
NEXT_PUBLIC_SUPABASE_ANON_KEY: true,
SUPABASE_URL: true,
SUPABASE_SERVICE_ROLE_KEY: true,
NODE_ENV: 'production'
}
[2025-03-28T16:42:12.559Z] [ERROR] Supabase query error: {
message: 'TypeError: fetch failed',
details: 'TypeError: fetch failed\n' +
' at node:internal/deps/undici/undici:12637:11\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
' at async l (/app/.next/server/app/api/health/route.js:1:1608)\n' +
' at async tr.do (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:18:17558)\n' +
' at async tr.handle (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:18:22072)\n' +
' at async doRender (/app/node_modules/next/dist/server/base-server.js:1452:42)\n' +
' at async responseGenerator (/app/node_modules/next/dist/server/base-server.js:1813:28)\n' +
' at async NextNodeServer.renderToResponseWithComponentsImpl (/app/node_modules/next/dist/server/base-server.js:1823:28)\n' +
' at async NextNodeServer.renderPageComponent (/app/node_modules/next/dist/server/base-server.js:2250:24)\n' +
' at async NextNodeServer.renderToResponseImpl (/app/node_modules/next/dist/server/base-server.js:2288:32)',
hint: '',
code: ''
}
I've also gone ahead and created some test endpoints for my app that bypass authentication & test connectivity with Supabase. Here's what they say when I open them on the railway deployed version of my app :
api/health
{"status":"ok","timestamp":"2025-03-28T16:55:20.865Z","environment":"production","isServer":true,"supabase":{"connected":false,"error":"TypeError: fetch failed"},"session":{"exists":false,"error":null},"env":{"NEXT_PUBLIC_SUPABASE_URL":true,"NEXT_PUBLIC_SUPABASE_ANON_KEY":true,"SUPABASE_URL":true,"SUPABASE_SERVICE_ROLE_KEY":true,"NODE_ENV":"production"}}
api/network-test
{"tests":[{"name":"DNS Resolution","success":true,"data":{"Status":0,"TC":false,"RD":true,"RA":true,"AD":false,"CD":false,"Question":[{"name":"supabase.co","type":1}],"Answer":[{"name":"supabase.co","type":1,"TTL":256,"data":"76.76.21.21"}]}},{"name":"Internet Connectivity","success":true,"status":200},{"name":"Supabase Connectivity","success":false,"error":"fetch failed"}],"timestamp":"2025-03-28T16:56:11.932Z"}
Another things I tried :
I've added every environmental variable that my Vercel app has to Railway (double and triple checked)
I've added Railway app URL to Supabase as Site URL :
humorous-curiosity-production-e6c8.up.railway.app
And configured all endpoints my app leads to as redirect URLs in Supabase :
Redirect URLs
https://humorous-curiosity-production-e6c8.up.railway.app
https://humorous-curiosity-production-e6c8.up.railway.app/login
https://humorous-curiosity-production-e6c8.up.railway.app/app
https://humorous-curiosity-production-e6c8.up.railway.app/callback
Total URLs: 4
I also checked my docker file for any port mismatch, and now it has this inside :
EXPOSE 8080
ENV PORT 8080
ENV HOSTNAME "0.0.0.0"
My Railway app is configured for 8080 as well.
I am not using any TCP or Proxy in my Railway app. I tried using TCP in Railway to point to port 3000 (default supabase port) - didn't help.
I've added this to my dockerfile in case there was a TLS/SSL issue :
FROM node:18-alpine AS base
# Install CA certificates
RUN apk add --no-cache ca-certificates
I'm using IPV6 on both railway & supabase.
My code is working properly in a v0-deployed Vercel :
https://stera-ai.vercel.app/, database is fully functional.
But cannot connect to Supabase when on Railway (the always "loading" state is the app trying to connect to Supabase but always getting TypeError: fetch failed).
1 Replies
a month ago
Hello,
This is likely because you are trying to connect to Supabase over IPv6, unfortunately, we do not support outbound IPv6, you will need to use the IPv4 option from Supabase.
Best,
Brody
Status changed to Awaiting User Response railway[bot] • about 1 month ago