Skip to content

Latest commit

 

History

History
289 lines (225 loc) · 5.28 KB

File metadata and controls

289 lines (225 loc) · 5.28 KB

🚀 QUICK DEPLOYMENT STEPS - Railway + Vercel

⚡ STEP-BY-STEP GUIDE (15 Minutes Total)


📋 PART 1: PUSH CODE TO GITHUB (3 minutes)

1. Open PowerShell in your project:

cd d:\DVS

2. Initialize Git (if not done):

git init
git add .
git commit -m "Initial commit"
git branch -M main

3. Create GitHub Repository:

  • Go to https://github.com/new
  • Name: blockchain-voting-system
  • Keep it Public
  • Don't initialize with README
  • Click "Create repository"

4. Push to GitHub:

git remote add origin https://github.com/YOUR_USERNAME/blockchain-voting-system.git
git push -u origin main

⚡ PART 2: DEPLOY BACKEND ON RAILWAY (5 minutes)

1. Install Railway CLI:

npm install -g @railway/cli

2. Login to Railway:

railway login

Browser opens → Click "Authorize" → Close browser

3. Navigate to backend folder:

cd d:\DVS\backend

4. Initialize Railway:

railway init
  • Select: "Create new Project"
  • Enter project name: voting-backend
  • Press Enter

5. Add PostgreSQL Database:

railway add
  • Select: "PostgreSQL"
  • Wait for deployment...

6. Link to GitHub (Optional but recommended):

railway link
  • Select your GitHub repo
  • Select service: voting-backend

7. Set Environment Variables:

railway variables set JWT_SECRET="my_super_secret_jwt_key_12345"
railway variables set SESSION_SECRET="my_super_secret_session_key_67890"
railway variables set NODE_ENV="production"

8. Deploy:

railway up

Wait 2-3 minutes for build...

9. Run Database Migrations:

railway run npm run migrate
railway run node create-superadmin.js

10. Get Your Backend URL:

railway status

Copy the URL - looks like: https://voting-backend-production-xxxx.up.railway.app

11. Generate Domain (if no URL shown):


🎨 PART 3: DEPLOY FRONTEND ON VERCEL (5 minutes)

1. Install Vercel CLI:

npm install -g vercel

2. Navigate to frontend:

cd d:\DVS\frontend

3. Create production env file:

echo REACT_APP_API_URL=https://YOUR_RAILWAY_URL/api > .env.production

Replace YOUR_RAILWAY_URL with actual Railway URL from Step 2.10

Example:

echo REACT_APP_API_URL=https://voting-backend-production-xxxx.up.railway.app/api > .env.production

4. Login to Vercel:

vercel login
  • Choose: GitHub
  • Browser opens → Authorize → Close browser

5. Deploy:

vercel

Answer the prompts:

  • Set up and deploy? Y
  • Which scope? [Your account] (press Enter)
  • Link to existing project? N
  • What's your project's name? voting-frontend (press Enter)
  • In which directory is your code? ./ (press Enter)
  • Want to override settings? N

Wait 2-3 minutes...

6. Deploy to Production:

vercel --prod

7. Get Your Frontend URL:

Look for: ✅ Production: https://voting-frontend-xxxx.vercel.app

Copy this URL!


🔧 PART 4: CONFIGURE CORS (2 minutes)

1. Update backend CORS to allow Vercel:

Open: d:\DVS\backend\src\server.js

Find this line (around line 24):

  origin: 'http://localhost:3000',

Replace with:

  origin: ['http://localhost:3000', 'https://voting-frontend-xxxx.vercel.app'],

Use your actual Vercel URL!

2. Commit and push:

cd d:\DVS
git add .
git commit -m "Update CORS for production"
git push

Railway will auto-redeploy in 2 minutes.


✅ PART 5: TEST YOUR DEPLOYMENT (2 minutes)

1. Open your frontend URL:

https://voting-frontend-xxxx.vercel.app

2. Test backend API:

Open in browser:

https://your-railway-backend-url.up.railway.app/

Should show: "Blockchain Voting System Backend Running"

3. Test login:

  • Use superadmin credentials created earlier
  • If you forgot, run:
railway run node create-superadmin.js

🎉 DEPLOYMENT COMPLETE!

Your Live URLs:


🔄 FUTURE UPDATES

To update backend:

cd d:\DVS
git add .
git commit -m "Your changes"
git push

Railway auto-deploys!

To update frontend:

cd d:\DVS
git add .
git commit -m "Your changes"
git push

Vercel auto-deploys!


🛠️ TROUBLESHOOTING

View Railway Logs:

cd d:\DVS\backend
railway logs

View Vercel Logs:

cd d:\DVS\frontend
vercel logs

Restart Railway Service:

railway restart

Redeploy Vercel:

vercel --prod --force

📞 NEED HELP?

Railway Issues:

Vercel Issues:


Total Time: ~15 minutes
Total Cost: $0.00 (100% FREE) 🎉