How to Get Railway Backend URL for Vercel
This guide shows you how to find your Railway backend URL and set it as NEXT_PUBLIC_API_URL in Vercel.
Step 1: Get Railway Backend URL
-
Go to Railway Dashboard
- Visit https://railway.app/dashboard
- Sign in if needed
-
Select Your Project
- Click on your project (the one containing your backend service)
-
Select Your Backend Service
- Click on the backend service (usually named after your repo or "backend")
-
Get the URL
- Go to the Settings tab
- Scroll down to Networking section
- You'll see a Domain section with your Railway-generated domain
- The URL will look like:
your-backend-name-production.up.railway.apporyour-backend-name.railway.app - Copy this entire URL (including the domain)
Alternative: You can also find it in the Deployments tab - click on a successful deployment and look for the domain/URL.
-
Add HTTPS Protocol
- Make sure to include
https://at the beginning - Full URL format:
https://your-backend-name-production.up.railway.app
- Make sure to include
Step 2: Set in Vercel
-
Go to Vercel Dashboard
- Visit https://vercel.com/dashboard
- Sign in if needed
-
Select Your Project
- Click on your frontend project
-
Go to Settings
- Click on the Settings tab
- Click on Environment Variables in the left sidebar
-
Add or Update NEXT_PUBLIC_API_URL
- Look for
NEXT_PUBLIC_API_URLin the list - If it exists, click the Edit button (three dots menu)
- If it doesn't exist, click Add New
- Set the following:
- Key:
NEXT_PUBLIC_API_URL - Value:
https://your-railway-backend-url.railway.app(paste the URL you copied from Railway) - Environment: Select all environments (Production, Preview, Development) or just Production
- Key:
- Click Save
- Look for
-
Redeploy
- After saving, Vercel will prompt you to redeploy
- Click Redeploy to apply the new environment variable
- Or go to Deployments tab and click Redeploy on the latest deployment
Step 3: Update Railway ALLOWED_ORIGINS
After setting up Vercel, you also need to update Railway's ALLOWED_ORIGINS to include your Vercel frontend URL:
-
Go back to Railway
- Navigate to your backend service
- Go to Variables tab
-
Update ALLOWED_ORIGINS
- Find
ALLOWED_ORIGINSvariable - Add your Vercel frontend URL(s) to the comma-separated list:
https://your-frontend.vercel.app,https://hivejournal.com,https://www.hivejournal.com - Save the variable
- Railway will automatically redeploy
- Find
Example URLs
Railway Backend URL examples:
https://hivejournal-backend-production.up.railway.apphttps://hivejournal-backend.railway.apphttps://backend-production-abc123.up.railway.app
Vercel Frontend URL examples:
https://hivejournal.vercel.apphttps://hivejournal-2026.vercel.apphttps://hivejournal.com(if custom domain is set)
Verify It's Working
-
Check Vercel Environment Variables
- Go to Vercel → Your Project → Settings → Environment Variables
- Verify
NEXT_PUBLIC_API_URLis set correctly
-
Test the Connection
- Visit your Vercel frontend URL
- Open browser DevTools → Network tab
- Try to use a feature that calls the backend API
- Check if requests are going to your Railway URL
-
Check Railway Logs
- Go to Railway → Your Service → Deployments
- Click on the latest deployment
- Check logs to see if requests are coming through
Troubleshooting
Issue: CORS Errors
- Solution: Make sure
ALLOWED_ORIGINSin Railway includes your Vercel frontend URL - Format:
https://your-frontend.vercel.app,https://your-custom-domain.com
Issue: 404 or Connection Refused
- Solution:
- Verify the Railway URL is correct (check for typos)
- Make sure Railway service is running (check deployments)
- Verify the URL includes
https://protocol
Issue: Environment Variable Not Updating
- Solution:
- Redeploy Vercel after adding/updating environment variables
NEXT_PUBLIC_*variables are baked into the build, so a new build is required
Issue: Can't Find Railway URL
- Solution:
- Make sure your Railway service has been deployed at least once
- Check the Networking section in Settings
- If no domain is shown, Railway may still be deploying - wait a few minutes
Quick Reference
Railway URL Location:
- Railway Dashboard → Your Project → Your Service → Settings → Networking → Domain
Vercel Environment Variable Location:
- Vercel Dashboard → Your Project → Settings → Environment Variables →
NEXT_PUBLIC_API_URL
Format:
NEXT_PUBLIC_API_URL=https://your-backend-name-production.up.railway.app