Skip to content

Deployment

The project deploys to two platforms simultaneously: Cloudflare (primary, production) and optionally cPanel (legacy fallback).

ServiceWhat
Cloudflare PagesFrontend (React/Vite build)
Cloudflare WorkersBackend (Express via serverless-http)
Cloudflare D1Database (SQLite)
Cloudflare R2File storage
Terminal window
cd frontend
npm run build # outputs to frontend/dist/
# Deploy dist/ to Cloudflare Pages
# Or connect the repo to Cloudflare Pages for automatic deploys on push

The frontend/public/_redirects and frontend/public/.htaccess files handle SPA routing (all paths → index.html).

Terminal window
cd backend
npx wrangler deploy

wrangler.toml defines the Worker configuration:

  • Entry point: worker.js (wraps Express via serverless-http)
  • D1 binding: DB → database shanvi-db
  • R2 binding: BUCKET → bucket shanvi-uploads
  • nodejs_compat flag: required for Node.js globals in Workers

⚠️ Critical: Rotate hardcoded secrets immediately

Section titled “⚠️ Critical: Rotate hardcoded secrets immediately”

wrangler.toml currently has JWT_SECRET and REFRESH_SECRET_KEY committed in plaintext. These values are compromised. To fix:

Terminal window
# Remove the [vars] entries for JWT_SECRET and REFRESH_SECRET_KEY from wrangler.toml
# Then set them as proper Cloudflare secrets:
npx wrangler secret put JWT_SECRET
npx wrangler secret put REFRESH_SECRET_KEY

Secrets set via wrangler secret put are encrypted at rest and never appear in the dashboard or source control.

Non-sensitive vars (like NODE_ENV, FRONTEND_URL) can stay in [vars]. Sensitive values must be Cloudflare secrets.

To apply schema changes to the production D1 database:

Terminal window
# Apply a SQL file to production D1
npx wrangler d1 execute shanvi-db --file=./your-migration.sql
# Apply to local D1 (for testing)
npx wrangler d1 execute shanvi-db --local --file=./your-migration.sql

The current codebase uses runtime ALTER TABLE guards instead of explicit migration files. This is a known issue — see Known Issues for context and the recommended migration approach.

The .cpanel.yml and backend/.htaccess files support deploying the Express server to a cPanel host as a traditional Node.js app with a MySQL database.

  1. Upload backend/ to the server
  2. Set environment variables in the Node.js app settings in cPanel
  3. Run npm install and set server.js as the entry point
  4. Point cPanel’s MySQL database credentials to .env
  1. Run npm run build locally
  2. Upload frontend/dist/ to the public_html directory
  3. The frontend/public/.htaccess handles SPA routing

There is currently no dedicated staging environment. The apist.shanvitravel.com.np domain (referenced in frontend/src/config/api.ts) appears to be used as a staging API, but this is not formally documented.

Recommendation: Set up a proper staging Worker (wrangler.toml environments) and Cloudflare Pages preview branch so new features can be tested before hitting production.

# Add to wrangler.toml
[env.staging]
name = "shanvi-travels-backend-staging"
vars = { NODE_ENV = "staging", FRONTEND_URL = "https://staging.shanvitravels.pages.dev" }
[[env.staging.d1_databases]]
binding = "DB"
database_name = "shanvi-db-staging"
database_id = "<staging-db-id>"