operations

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

  1. Go to Railway Dashboard

  2. Select Your Project

    • Click on your project (the one containing your backend service)
  3. Select Your Backend Service

    • Click on the backend service (usually named after your repo or "backend")
  4. 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.app or your-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.

  5. Add HTTPS Protocol

    • Make sure to include https:// at the beginning
    • Full URL format: https://your-backend-name-production.up.railway.app

Step 2: Set in Vercel

  1. Go to Vercel Dashboard

  2. Select Your Project

    • Click on your frontend project
  3. Go to Settings

    • Click on the Settings tab
    • Click on Environment Variables in the left sidebar
  4. Add or Update NEXT_PUBLIC_API_URL

    • Look for NEXT_PUBLIC_API_URL in 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
    • Click Save
  5. 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:

  1. Go back to Railway

    • Navigate to your backend service
    • Go to Variables tab
  2. Update ALLOWED_ORIGINS

    • Find ALLOWED_ORIGINS variable
    • 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

Example URLs

Railway Backend URL examples:

  • https://hivejournal-backend-production.up.railway.app
  • https://hivejournal-backend.railway.app
  • https://backend-production-abc123.up.railway.app

Vercel Frontend URL examples:

  • https://hivejournal.vercel.app
  • https://hivejournal-2026.vercel.app
  • https://hivejournal.com (if custom domain is set)

Verify It's Working

  1. Check Vercel Environment Variables

    • Go to Vercel → Your Project → Settings → Environment Variables
    • Verify NEXT_PUBLIC_API_URL is set correctly
  2. 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
  3. 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_ORIGINS in 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
GET RAILWAY URL — Docs | HiveJournal