This guide explains how to host the AegisExpress Logistics application and connect the client to the API.
The application consists of two parts:
- Frontend (Client): React TypeScript application
- Backend (API): Node.js Express server
- Node.js (v18+ recommended)
- npm or yarn
- MongoDB (Atlas or local)
- Redis (Upstash or local)
- Clone the repository:
git clone https://github.com/RabbitDaCoder/ExpressLogistics.git
cd ExpressLogistics- Setup API Environment:
cd api
cp .env.example .envEdit api/.env:
# Server
PORT=5000
NODE_ENV=development
CLIENT_ORIGIN=http://localhost:5173
# Database
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/logisticsDB
# JWT
JWT_SECRET=your_jwt_secret_here
JWT_EXPIRES=7d
# Redis
REDIS_URL=redis://localhost:6379
# Admin Seeding
ADMIN_SEED_TOKEN=CHANGE_ME
ADMIN_EMAIL=owner@example.com
ADMIN_PASSWORD=Rabbit522@
# Email (Optional)
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465- Setup Client Environment:
cd ../clientCreate client/.env.local:
VITE_API_BASE_URL=http://localhost:5000- Start API Server:
cd api
npm install
npm run dev- Start Client:
cd ../client
npm install
npm run dev- Seed Initial Admin:
cd api
npm run dev -- --seed-admin- Access Application:
- Client: http://localhost:5173
- API: http://localhost:5000
- Admin: http://localhost:5173/owner/login
-
Create Render Account: https://render.com
-
Connect GitHub: Link your repository
-
Create Web Service:
- Build Command:
cd api && npm install - Start Command:
cd api && npm start - Environment: Node.js
- Instance Type: Free tier available
- Build Command:
-
Environment Variables (in Render dashboard):
NODE_ENV=production
PORT=10000
MONGO_URI=mongodb+srv://...
JWT_SECRET=production_secret_here
REDIS_URL=rediss://...
CLIENT_ORIGIN=https://your-frontend-domain.vercel.app
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
ADMIN_EMAIL=owner@example.com
ADMIN_PASSWORD=Passw0rd!-
Create Vercel Account: https://vercel.com
-
Import GitHub Repository
-
Configuration:
- Framework: React
- Root Directory:
client - Build Command:
npm run build - Output Directory:
dist
-
Environment Variables (in Vercel dashboard):
VITE_API_URL=https://your-api-name.onrender.com- Create Railway Account: https://railway.app
- Deploy from GitHub:
- Select monorepo option
- Configure separate services for API and Client
- Create Heroku app
- Set buildpack to Node.js
- Configure environment variables
- Deploy via GitHub integration
- Create Netlify account
- Connect GitHub repository
- Set build settings:
- Base directory:
client - Build command:
npm run build - Publish directory:
client/dist
- Base directory:
- Create Atlas Account: https://mongodb.com/atlas
- Create Cluster:
- Choose free tier (M0)
- Select closest region
- Configure Access:
- Add database user
- Configure IP whitelist (0.0.0.0/0 for production)
- Get Connection String:
- Replace
<password>and<dbname> - Add to MONGO_URI environment variable
- Replace
- Create Upstash Account: https://upstash.com
- Create Redis Database:
- Choose free tier
- Select closest region
- Copy Connection Details:
- Get REDIS_URL from dashboard
- Add to environment variables
The client connects to the API via environment variables:
Development:
# client/.env.local
VITE_API_URL=http://localhost:5000Production:
# Vercel environment variables
VITE_API_URL=https://your-api-domain.onrender.comThe API must allow client origins:
// api/app.js
app.use(
cors({
origin: [
process.env.CLIENT_ORIGIN || "http://localhost:5173",
"https://your-frontend-domain.vercel.app",
// Add your production client URL
],
credentials: true,
})
);- Health Check API:
curl https://your-api-domain.onrender.com/api/health- Client API Test:
- Open browser developer tools
- Check Network tab for API calls
- Verify requests go to correct API URL
- Vercel: Automatic SSL for custom domains
- Render: Automatic SSL for .onrender.com domains
- Netlify: Automatic SSL with Let's Encrypt
-
API Custom Domain (Render):
- Add custom domain in dashboard
- Update DNS CNAME records
- SSL automatically provisioned
-
Client Custom Domain (Vercel):
- Add domain in project settings
- Configure DNS records
- SSL automatically handled
- Never commit
.envfiles to Git - Use different secrets for production
- Rotate JWT secrets regularly
// Restrict origins in production
origin: ["https://yourdomain.com", "https://www.yourdomain.com"];// Already configured in app.js
const publicLimiter = rateLimit({
windowMs: 60 * 1000,
max: 120,
});- API: GET
/api/health - Database: Connection status in health endpoint
- Redis: Connection status in health endpoint
- Check platform logs (Render/Vercel dashboards)
- Monitor error rates
- Set up alerts for downtime
- Development: Test changes locally
- Staging: Deploy to staging environment
- Production: Deploy via GitHub push (automatic)
-
CORS Errors:
- Check CLIENT_ORIGIN environment variable
- Verify API CORS configuration
- Ensure HTTPS/HTTP consistency
-
Database Connection:
- Verify MONGO_URI format
- Check Atlas IP whitelist
- Test connection string locally
-
Build Failures:
- Check Node.js version compatibility
- Verify all dependencies in package.json
- Review build logs in platform dashboard
-
API Not Responding:
- Check server logs
- Verify environment variables
- Test health endpoint
Local Testing:
# Test API health
curl http://localhost:5000/api/health
# Test client build
cd client && npm run build
# Check API logs
cd api && npm run devProduction Testing:
# Test production API
curl https://your-api.onrender.com/api/health
# Test client connection
curl https://your-client.vercel.app- Environment variables configured
- Database connection tested
- Redis connection tested
- Build process verified
- API health endpoint working
- Health check passes
- Admin login works
- Client-API connection verified
- Email functionality tested (if configured)
- SSL certificates active
- Custom domains configured (if applicable)
- Regular backups configured
- Monitoring alerts set up
- Update schedule planned
- Error tracking implemented