|
| 1 | +# LanguageGO Railway Deployment Guide |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | +- GitHub account |
| 5 | +- Railway account (free): https://railway.app |
| 6 | +- Firebase project with service account key |
| 7 | +- Clerk account for authentication |
| 8 | + |
| 9 | +## Step 1: Set up Firebase Service Account |
| 10 | +1. Go to your Firebase Console: https://console.firebase.google.com |
| 11 | +2. Select your project |
| 12 | +3. Go to Project Settings > Service Accounts |
| 13 | +4. Click "Generate new private key" |
| 14 | +5. Save the JSON file securely - you'll need its contents for environment variables |
| 15 | + |
| 16 | +## Step 2: Deploy to Railway |
| 17 | + |
| 18 | +### Deploy the Java Backend |
| 19 | +1. Go to https://railway.app and sign in with GitHub |
| 20 | +2. Click "New Project" → "Deploy from GitHub repo" |
| 21 | +3. Select `FloppyDoval/LanguageGO` |
| 22 | +4. Railway will detect multiple services, choose to deploy the **backend first** |
| 23 | +5. Configure the backend service: |
| 24 | + - **Root Directory**: `server` |
| 25 | + - Railway should auto-detect it's a Java/Maven project |
| 26 | + - **Start Command**: `java -cp target/classes:target/lib/* edu.brown.cs.student.main.server.Server` |
| 27 | + |
| 28 | +6. **Environment Variables** (in Railway dashboard): |
| 29 | + - `FIREBASE_CREDENTIALS`: Paste the entire contents of your Firebase service account JSON |
| 30 | + - `PORT`: Railway will automatically set this |
| 31 | + |
| 32 | +7. Deploy and note the generated URL (e.g., `https://your-backend-name.railway.app`) |
| 33 | + |
| 34 | +### Deploy the React Frontend |
| 35 | +1. In the same Railway project, click "New Service" |
| 36 | +2. Choose "GitHub Repo" and select the same repository |
| 37 | +3. Configure the frontend service: |
| 38 | + - **Root Directory**: `client` |
| 39 | + - Railway should auto-detect it's a Node.js project |
| 40 | + - Build command will be automatically detected: `npm run build` |
| 41 | + - Start command: `npm run serve` (or Railway will serve the built files) |
| 42 | + |
| 43 | +4. **Environment Variables**: |
| 44 | + - `VITE_API_URL`: Use the backend URL from step 7 above |
| 45 | + - `VITE_CLERK_PUBLISHABLE_KEY`: Your Clerk publishable key from Clerk dashboard |
| 46 | + - `NODE_ENV`: `production` |
| 47 | + |
| 48 | +5. Deploy the frontend |
| 49 | + |
| 50 | +## Step 3: Verify Deployment |
| 51 | +1. **Backend Health Check**: Visit `https://your-backend-url/ping` - should return "pong" |
| 52 | +2. **Frontend**: Visit your frontend URL - should load the application |
| 53 | +3. **API Integration**: Test that frontend can communicate with backend |
| 54 | + |
| 55 | +## Step 4: Configure CORS (if needed) |
| 56 | +Your Java server already has CORS configured to allow all origins (`*`). For production, you might want to restrict this to your frontend domain only. |
| 57 | + |
| 58 | +## Environment Variables Summary |
| 59 | + |
| 60 | +### Backend Service |
| 61 | +- `FIREBASE_CREDENTIALS`: Your complete Firebase service account JSON |
| 62 | +- `PORT`: (Automatically set by Railway) |
| 63 | + |
| 64 | +### Frontend Service |
| 65 | +- `VITE_API_URL`: Your Railway backend URL |
| 66 | +- `VITE_CLERK_PUBLISHABLE_KEY`: Your Clerk publishable key |
| 67 | +- `NODE_ENV`: `production` |
| 68 | + |
| 69 | +## Local Development |
| 70 | +Use the provided script: |
| 71 | +```bash |
| 72 | +./start-local.sh |
| 73 | +``` |
| 74 | + |
| 75 | +## Troubleshooting |
| 76 | +- **Build Failures**: Check Railway logs in the dashboard |
| 77 | +- **503 Errors**: Backend might be starting up (Railway has no cold starts) |
| 78 | +- **API Connection Issues**: Verify `VITE_API_URL` points to correct backend URL |
| 79 | +- **Firebase Issues**: Ensure `FIREBASE_CREDENTIALS` is properly formatted JSON |
| 80 | +- **Maven Issues**: Railway should automatically detect Java 17 from `pom.xml` |
| 81 | + |
| 82 | +## Railway Advantages |
| 83 | +- ✅ Native Java/Maven support |
| 84 | +- ✅ No cold starts (unlike Render free tier) |
| 85 | +- ✅ Automatic deployments on Git push |
| 86 | +- ✅ Built-in database options |
| 87 | +- ✅ Easy environment variable management |
| 88 | +- ✅ Generous free tier ($5/month credit) |
| 89 | + |
| 90 | +## Production Considerations |
| 91 | +- Consider using Railway's database services for production data |
| 92 | +- Set up custom domains for your services |
| 93 | +- Monitor usage to stay within free tier limits |
| 94 | +- Configure proper CORS origins for security |
0 commit comments