Complete guide for deploying QueryLab frontend and backend.
First, clone the repository from GitHub:
git clone https://github.com/zamdevio/querylab.git
cd querylab- Cloudflare account
- Wrangler CLI installed:
npm install -g wrangler - Repository cloned from
https://github.com/zamdevio/querylab.git
Edit Backend/wrangler.jsonc:
Note: FRONTEND_URL can be set as a Wrangler secret or in vars. It's recommended to set it as a secret for production.
Set required secrets using Wrangler (these are stored securely and not in your code):
cd Backend
wrangler secret put DEEPSEEK_KEY
# Enter your DeepSeek API key when prompted
wrangler secret put JWT_SECRET
# Enter a strong random string for JWT signing
wrangler secret put RESEND_API_KEY
# Enter your Resend API key when prompted
wrangler secret put EMAIL_FROM
# Enter your email sender address (e.g., "QueryLab <noreply@yourdomain.com>")
wrangler secret put FRONTEND_URL
# Enter your frontend URL (e.g., "https://your-frontend-domain.com")
# Optional: Can also be set in wrangler.jsonc vars
wrangler secret put COOKIE_DOMAIN
# Enter your cookie domain (e.g., ".yourdomain.com" with leading dot for subdomain sharing)
# Required in production when using secure cross-origin cookiesImportant:
- Never commit secrets to GitHub. Use Wrangler secrets for production.
ENVIRONMENTmust be set inwrangler.jsoncvars (not as a secret)COOKIE_DOMAINis required in production for cross-origin cookie sharing
npm run deployOr for a specific environment:
wrangler deploy --env productionCheck your Worker URL:
https://your-worker.your-subdomain.workers.dev
Test the health endpoint:
curl https://your-worker.your-subdomain.workers.dev/health- Cloudflare account
- Repository cloned from
https://github.com/zamdevio/querylab.git - Backend API URL configured
In Cloudflare Pages settings, set:
NEXT_PUBLIC_API_URL: Your backend Worker URL
Build command:
npm run buildOutput directory:
.next
- Connect your GitHub repository
- Select the
Frontenddirectory as root - Set build command:
npm run build - Set output directory:
.next - Deploy
- Go to Pages settings
- Add custom domain
- Update DNS records as instructed
- SSL certificate is automatic
npm install -g vercelcd Frontend
vercelIn Vercel dashboard:
NEXT_PUBLIC_API_URL: Your backend API URL
- Add custom domain in Vercel settings
- Update DNS records
- SSL is automatic
Required in wrangler.jsonc vars:
ENVIRONMENT:"development"or"production"(required - only in vars)
Required as Wrangler secrets or in .dev.vars:
DEEPSEEK_KEY: DeepSeek API keyJWT_SECRET: Secret for JWT signingRESEND_API_KEY: Resend API key for emailsEMAIL_FROM: Email sender address
Optional (can be secret, vars, or .dev.vars):
FRONTEND_URL: Frontend domain URL (defaults tohttp://localhost:3000in development)
Required in production (can be secret, vars, or .dev.vars):
COOKIE_DOMAIN: Cookie domain for cross-origin cookies (required when using secure cookies in production). Example:.zamdev.dev(with leading dot for subdomain sharing)
Required in build environment:
NEXT_PUBLIC_API_URL: Backend API URL
Ensure backend CORS allows your frontend domain:
In Backend/src/lib/config.ts:
frontendUrl: env.FRONTEND_URL || 'https://your-frontend-domain.com'For cross-origin cookies (different subdomains):
SameSite=NoneSecure=true(HTTPS only)- No
Domainattribute
- Automatic SSL for Workers
- Automatic SSL for Pages
- Free SSL certificates
- Automatic SSL
- Free certificates
- Custom domain support
- View logs in Cloudflare dashboard
- Monitor requests and errors
- Set up alerts for failures
- Use browser DevTools
- Monitor network requests
- Check console for errors
- Check Worker logs in Cloudflare dashboard
- Verify secrets are set correctly
- Check CORS configuration
- Verify Worker is deployed
- Verify
NEXT_PUBLIC_API_URLis set - Check CORS allows frontend domain
- Verify backend is deployed and accessible
- Check browser console for errors
- Ensure
SameSite=NoneandSecure=true - Verify both frontend and backend use HTTPS
- Check CORS credentials setting
- Verify cookie domain settings
- Use Durable Objects for state
- Implement caching where appropriate
- Monitor Worker execution time
- Optimize database queries
- Enable Next.js static optimization
- Use image optimization
- Implement code splitting
- Cache static assets
- HTTPS enabled on all domains
- Environment variables set securely
- CORS configured correctly
- Rate limiting enabled
- JWT secrets are strong
- Cookies are httpOnly and Secure
- API keys are stored as secrets
- Error messages don't leak sensitive info
{ "name": "querylab-api", "compatibility_date": "2024-01-01", "main": "src/app.ts", "vars": { "ENVIRONMENT": "production" } }