1. Backend Deployment on Vercel

1.1. Deploy Backend to Vercel

Prerequisites

  • GitHub account

  • Vercel account (sign up at https://vercel.com using GitHub Account)

  • Backend code pushed to GitHub repository

Deployment Steps

  1. Connect GitHub Repository

    • Log in to Vercel dashboard

    • Click “Add New Project”

    • Import your GitHub repository containing the backend code

    • Select the repository

  2. Configure Project Settings

    • Root Directory: Select backend folder

    • Framework Preset: Select “Other” or leave as auto-detected

    • Build Command: Leave empty (Vercel will auto-detect Python)

    • Output Directory: Leave empty

  3. Set Environment Variables

    Click “Environment Variables” and add:

    • Name: GEMINI_API_KEY

    • Value: Your Google Gemini API key

    Click “Save” for each environment variable

  4. Deploy

    • Click “Deploy”

    • Wait for deployment to complete

    • Copy the deployment URL (e.g., https://your-project.vercel.app)

  5. Verify Deployment

    Visit https://your-project.vercel.app/ in your browser. You should see:

    {
      "status": "ok",
      "message": "Pregnancy AI Assistant",
      "indexed_pages": 45,
      "topics": 5
    }
    

Configuration Files

The backend includes vercel.json which configures: - Python runtime - Route handling for all requests to main.py

No additional configuration needed for basic deployment.

1.2. Update Backend API URL

After deploying the backend, update the frontend to use the new API URL.

Method 2: Direct Configuration

Edit frontend/nuxt.config.js:

publicRuntimeConfig: {
  deployEnv: process.env.DEPLOY_ENV || 'local',
  basePath: process.env.DEPLOY_ENV === "GH_PAGES" ? "/pregnancy-app" : "",
  backendApiUrl: process.env.BACKEND_API_URL || 'https://your-backend.vercel.app'
},

Replace https://your-backend.vercel.app with your actual Vercel deployment URL.

Usage in Components

The backend API URL is accessed in components via:

computed: {
  backendApiUrl() {
    return this.$config.publicRuntimeConfig?.backendApiUrl || 'https://pregnancy-app-tau.vercel.app';
  }
},

Then use it in API calls:

const response = await fetch(`${this.backendApiUrl}/chat`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ message: userMessage })
});

1.3. Troubleshooting

Deployment fails
  • Ensure vercel.json exists in the backend directory

  • Check that all dependencies are listed in requirements.txt

  • Verify environment variables are set correctly

API returns 500 error
  • Check Vercel function logs in the dashboard

  • Verify GEMINI_API_KEY is set correctly

  • Ensure embeddings.json exists in backend/data/

CORS errors
  • Backend CORS is configured to allow all origins by default

  • If issues persist, check core/config.py CORS settings