This guide will walk you through the steps to deploy the Stock Market Dashboard application to Vercel.
-
Login to Vercel:
- Go to Vercel and sign in or create an account
- Connect your GitHub account if not already connected
-
Create a new project for the backend:
- Click "Add New..." → "Project"
- Select your "Stock-Market-Dashboard" repository
- Configure the project:
- Project Name:
stock-market-dashboard-backend - Framework Preset:
Other - Root Directory:
backend - Build Command:
npm install - Output Directory: (leave blank)
- Install Command:
npm install - Development Command:
npm start
- Project Name:
-
Set environment variables (if needed):
- Click on "Environment Variables"
- Add any required environment variables:
NODE_ENV:productionPORT:8080(Vercel will override this, but include it anyway)
-
Deploy:
- Click "Deploy"
- Wait for the deployment to complete
- Note the deployment URL (e.g.,
https://stock-market-dashboard-backend.vercel.app)
-
Create a new project for the frontend:
- Click "Add New..." → "Project"
- Select your "Stock-Market-Dashboard" repository again
- Configure the project:
- Project Name:
stock-market-dashboard-frontend - Framework Preset:
Create React App - Root Directory:
frontend - Build Command:
npm run build - Output Directory:
build - Install Command:
npm install - Development Command:
npm start
- Project Name:
-
Set environment variables:
- Click on "Environment Variables"
- Add the API URL environment variable:
- Name:
REACT_APP_API_URL - Value:
https://stock-market-dashboard-backend.vercel.app/api(replace with your actual backend URL)
- Name:
-
Deploy:
- Click "Deploy"
- Wait for the deployment to complete
- Note the deployment URL (e.g.,
https://stock-market-dashboard-frontend.vercel.app)
- Visit your frontend deployment URL
- Check that the application loads correctly
- Verify that you can see the list of companies and stock charts
- If you encounter any issues, check the deployment logs in Vercel
If you're experiencing CORS issues:
- Go to your backend project in Vercel
- Update the environment variables:
- Add a variable
ALLOWED_ORIGINSwith the URL of your frontend
- Add a variable
If the frontend can't connect to the backend:
- Check that the
REACT_APP_API_URLis set correctly - Make sure the URL includes
/apiat the end - Verify that your backend is working by accessing a direct API endpoint (e.g.,
https://stock-market-dashboard-backend.vercel.app/api/companies)
Vercel automatically deploys your application whenever you push changes to your GitHub repository. To deploy a new version:
- Make your changes locally
- Commit them to Git:
git add . git commit -m "Your commit message" git push origin master
- Vercel will automatically deploy the new version