Skip to main content

Overview

Deploy the FitAiid frontend Progressive Web App (PWA) to Vercel, a platform optimized for static sites and SPAs with automatic SSL, global CDN, and instant rollbacks.
Estimated Time: 10 minutes
Difficulty: ⭐ (Very Easy)

Prerequisites

1

Backend Deployed

Your backend should be deployed to Railway and you should have the API URL:
https://fitaiid-api.railway.app
2

GitHub Repository

Frontend code should be in the frontend/ directory of your GitHub repository.

Vercel Setup

1. Create Vercel Account

1

Sign Up

Navigate to vercel.com and click “Sign Up”
2

Connect GitHub

Choose GitHub as your authentication method and authorize Vercel.
3

Grant Permissions

Allow Vercel to access your GitHub repositories.

2. Import Project

1

Add New Project

In Vercel dashboard, click “Add New…”“Project”
2

Select Repository

Find and select your FitAidd repository from the list.
3

Configure Build Settings

  • Framework Preset: Other (vanilla HTML/CSS/JS)
  • Root Directory: frontend/IMPORTANT
  • Build Command: (leave empty)
  • Output Directory: . (current directory)
Always set Root Directory to frontend/ to deploy only the frontend portion of the monorepo.

Configure Environment Variables

The frontend needs to know where your backend API is located.

Add API URL

1

Environment Variables Tab

In the import project screen, expand “Environment Variables”
2

Add API URL

Add the following variable:
NameValue
VITE_API_URLhttps://fitaiid-api.railway.app
3

Environment Scope

Select Production, Preview, and Development for all environments.
Replace https://fitaiid-api.railway.app with your actual Railway backend URL.

Update Frontend Configuration

Configure API Endpoint

Ensure your config.js points to the production backend:
const CONFIG = {
    // Auto-detect environment and use appropriate API URL
    API_URL: window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
        ? 'http://localhost:5000'
        : 'https://fitaiid-production.up.railway.app', // Your Railway URL

    // Session timeout (24 hours)
    SESSION_TIMEOUT: 24 * 60 * 60 * 1000,

    // PWA configuration
    PWA: {
        NAME: 'FitAiid',
        SHORT_NAME: 'FitAiid'
    }
};

// Freeze config to prevent modifications
if (typeof Object.freeze === 'function') {
    Object.freeze(CONFIG);
}

console.log('⚙️ Frontend config loaded:', CONFIG.API_URL);

Update API URL for Production

If your config still points to localhost, update it:
# Update frontend/scripts/config.js with your Railway URL
git add frontend/scripts/config.js
git commit -m "Update API URL for production"
git push origin main
Vercel automatically detects GitHub pushes and redeploys your application.

Deploy to Vercel

1

Start Deployment

Click “Deploy” button in Vercel.
2

Monitor Build

Watch the build logs in real-time. You should see:
Cloning repository...
Installing dependencies...
Building application...
 Build completed in 45s
Deploying to production...
 Deployment successful
3

Get Deployment URL

Once deployed, Vercel provides a URL:
https://fitaiid.vercel.app
Copy this URL to access your application.

Progressive Web App Features

The FitAiid frontend is a full PWA with advanced features:

Service Worker

The service worker handles offline functionality and push notifications:
frontend/service-worker.js
const CACHE_NAME = 'fitaiid-v1';
const urlsToCache = [
  '/',
  '/index.html',
  '/pages/home.html',
  '/pages/login.html',
  '/scripts/config.js',
  '/styles/index.css'
];

// Install service worker and cache assets
self.addEventListener('install', (event) => {
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then((cache) => cache.addAll(urlsToCache))
  );
});

// Fetch from cache first, fallback to network
self.addEventListener('fetch', (event) => {
  event.respondWith(
    caches.match(event.request)
      .then((response) => response || fetch(event.request))
  );
});

Offline-First Architecture

Cache Strategy

Assets are cached on first visit, enabling offline access to previously viewed pages.

Push Notifications

Web Push API integration allows real-time workout reminders and updates.

Background Sync

Failed API requests are queued and retried when connection is restored.

Install Prompt

Users can install FitAiid as a native app on mobile and desktop.

Frontend Architecture

Project Structure

frontend/
├── index.html              # Landing page
├── manifest.json           # PWA configuration
├── service-worker.js       # Service worker for offline/push
├── pages/                  # HTML pages
│   ├── home.html
│   ├── login.html
│   ├── register.html
│   ├── perfil.html
│   ├── estadisticas.html
│   ├── entrenador.html
│   ├── nutricion.html
│   └── chatbot.html
├── scripts/                # JavaScript modules
│   ├── config.js           # API configuration
│   ├── auth-guard.js       # Route protection
│   ├── notifications.js    # Push notification system
│   ├── home.js
│   ├── login.js
│   └── register.js
├── styles/                 # CSS files
│   ├── index.css           # Global styles
│   ├── login.css
│   ├── register.css
│   └── perfil.css
└── img/                    # Images and assets
    ├── servicios/
    ├── calculadoras/
    └── nutricion/

Authentication Flow

Verify Deployment

Test Core Functionality

1

Access Application

Open your Vercel URL in a browser:
https://fitaiid.vercel.app
2

Test Login

Navigate to /pages/login.html and test authentication:
You should be redirected to /pages/home.html after successful login.
3

Verify API Connection

Open browser DevTools (F12) → Network tab and confirm API requests go to your Railway URL:
https://fitaiid-api.railway.app/api/...
4

Test Service Worker

DevTools → Application → Service WorkersVerify status shows: ✅ activated and running
5

Test Push Notifications

Click the bell icon 🔔 and enable notifications. Check DevTools console for:
✅ Service Worker registered
✅ Push subscription created

Test PWA Installation

  1. Look for the install icon in the address bar
  2. Click “Install FitAiid”
  3. Application opens in standalone window

Update CORS in Backend

After deploying to Vercel, you must update your backend CORS configuration to allow requests from your new domain.

Update Railway Environment Variables

1

Open Railway Dashboard

Navigate to your Railway project
2

Update CORS_ORIGINS

Update the CORS_ORIGINS variable to include your Vercel URL:
https://fitaiid.vercel.app,http://localhost:3000
3

Redeploy Backend

Click “Redeploy” to apply the changes

Alternative: Update Code

Or update CORS directly in your backend code:
backend/src/app.js
const corsOptions = {
  origin: [
    'https://fitaiid.vercel.app',      // Production frontend
    'http://localhost:3000',           // Local development
    'http://localhost:5000'            // Local testing
  ],
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
  allowedHeaders: ['Content-Type', 'Authorization']
};

app.use(cors(corsOptions));
Then commit and push:
git add backend/src/app.js
git commit -m "Update CORS for production frontend"
git push origin main

Troubleshooting

Symptom:
Access to XMLHttpRequest blocked by CORS policy
Solution:
  1. Add your Vercel URL to backend CORS whitelist
  2. Ensure credentials: true is set in CORS config
  3. Verify Railway backend has redeployed with new settings
Symptom:
Failed to register ServiceWorker: SecurityError
Solution:
  1. Service workers require HTTPS (Vercel provides this automatically)
  2. Verify service-worker.js is in the root of frontend/ directory
  3. Check browser console for syntax errors in service worker code
  4. Clear browser cache and hard reload (Ctrl+Shift+R)
Symptom:
Cannot read property 'API_URL' of undefined
Solution:
  1. Verify config.js is loaded before other scripts in HTML:
<script src="/scripts/config.js"></script>
<script src="/scripts/home.js"></script>
  1. Check config.js has correct Railway URL
  2. Test API URL manually in browser
Symptom:
Notification permission denied
Solution:
  1. Check browser notification permissions (click padlock in address bar)
  2. Verify VAPID keys are configured in Railway backend
  3. Test on different browser (some block notifications by default)
  4. Check DevTools → Application → Service Workers for errors
Symptom:
Build Error: No Build Output found
Solution:
  1. Verify Root Directory is set to frontend/
  2. Ensure index.html exists in frontend directory
  3. Check for syntax errors in HTML/CSS/JS files
  4. Review Vercel build logs for specific errors

Custom Domain (Optional)

Add a custom domain to your Vercel deployment:
1

Purchase Domain

Buy a domain from a registrar like Namecheap, GoDaddy, or Google Domains
2

Add Domain in Vercel

Go to your project → Settings → Domains → Add Domain
3

Configure DNS

Add these records to your domain’s DNS:
TypeNameValue
A@76.76.21.21
CNAMEwwwcname.vercel-dns.com
4

Verify Domain

Wait 24-48 hours for DNS propagation. Vercel will automatically provision an SSL certificate.

Performance Optimization

Edge Caching

Vercel’s global CDN caches static assets at edge locations for under 50ms response times.

Automatic Compression

Gzip and Brotli compression applied automatically to all assets.

Image Optimization

Use Vercel’s Image Optimization API for responsive images.

Code Splitting

Consider splitting large JavaScript files for faster initial loads.

Deployment Metrics

Monitor your deployment in Vercel Dashboard:
  • Deployment Frequency: Automatic on every GitHub push
  • Build Time: ~30-60 seconds
  • Global Latency: Under 50ms (edge locations)
  • Uptime SLA: 99.99%

Next Steps

Configure Environment Variables

Learn about all the environment variables needed for FitAiid and how to obtain the API keys.

Build docs developers (and LLMs) love