Web Deployment Guide (Local & Render Cloud)
lynx-anchor
lynx-anchor
lynx-anchor
lynx-anchor
lynx-anchor
lynx-anchor
This guide provides complete, step-by-step instructions for testing the Retail POS Web Applicationlocally and deploying it to Render.com so users can access the application from any web browser.
Table of Contents
- Overview & Architecture
- Prerequisites
- Phase 1: Local Web Testing
- Phase 2: Deploying to Render.com
- Environment Variables Reference
- Troubleshooting & FAQ
Overview & Architecture
The web application combines the Flutter Webuser interface with the **Express.js (Node.js)**backend API into a single unified deployment model:
[ Web Browser User ] ──(HTTPS)──> [ Express Backend Server on Render ]
│
├──> Serves Static Web UI (Flutter SPA)
└──> Handles REST API (/api/v1/...) ──> [ Render PostgreSQL DB ]
Key Highlights:
- **Zero Configuration for Users:**When users visit
https://your-app.onrender.com, the Flutter Web interface loads automatically and connects to the backend on the same domain (Uri.base.origin). - **Non-Breaking Design:**Desktop (Windows/Linux/macOS) and mobile (Android/iOS) apps continue using offline
server_config.jsonwithout any changes.
Prerequisites
Before deploying, ensure you have:
- Flutter SDK installed locally (v3.x+).
- Node.js (v20+ LTS) installed locally.
- A free account on Render.com.
- Git installed and your repository pushed to GitHub or GitLab.
Phase 1: Local Web Testing
Test the web app on your local machine before deploying to Render.
Step 1: Build Flutter Web Release
Open a terminal in the root project folder (RetailSale) and run:
flutter build web --release
This generates compiled web assets in the build/web/ directory.
Step 2: Copy Web Build to Backend Static Folder
Copy the output from build/web/ into backend/public/:
Windows (PowerShell):
if (!(Test-Path "backend\public")) { New-Item -ItemType Directory -Path "backend\public" }
Copy-Item -Path "build\web\*" -Destination "backend\public" -Recurse -Force
macOS / Linux (Bash):
mkdir -p backend/public
cp -r build/web/* backend/public/
Step 3: Run the Backend Server Locally
Navigate to the backend folder and start the server:
cd backend
npm install
node server.js
Step 4: Verify in Web Browser
- Open Google Chrome, Edge, or Safari and go to:
- Web UI:
http://localhost:3000 - API Health Check:
http://localhost:3000/health
- Web UI:
- Test user login, registration, dashboard loading, and sales screen.
Phase 2: Deploying to Render.com
Option A: Automatic Blueprint Deployment (Recommended)
Render can automatically build and provision both the PostgreSQL database and the unified Web + API service using render.yaml.
-
Push Changes to GitHub: Ensure
render.yamlandDockerfile.webare committed:git add .
git commit -m "Add Web deployment config"
git push origin main -
Deploy on Render:
- Log into your Render Dashboard.
- Click New +→ Blueprint.
- Connect your GitHub repository (
RetailSale). - Render will detect
render.yamland prompt you to create:- Database:
retail-sale-db(PostgreSQL) - Web Service:
retail-sale-backend(usingDockerfile.web)
- Database:
- Click Apply.
-
Access Your Live Web App: Once the build completes (usually 2-4 minutes), open your service URL:
https://<your-app-name>.onrender.com
Option B: Manual Docker Web Service Deployment
If you prefer setting up services manually on Render:
Step 1: Create PostgreSQL Database on Render
- In Render Dashboard, click New +→ PostgreSQL.
- Name:
retail-sale-db - Database Name:
retailsale_db - User:
retailsale_user - Plan:
Free - Click Create Databaseand copy the Internal Database URL.
Step 2: Create Web Service on Render
- In Render Dashboard, click New +→ Web Service.
- Connect your GitHub repository.
- Configure the settings:
| Setting | Value |
|---|---|
| Name | retail-sale-web |
| Language / Runtime | Docker |
| Dockerfile Path | ./Dockerfile.web |
| Docker Context | . |
| Branch | main |
| Plan | Free |
- Under Environment Variables, add:
| Key | Value |
|---|---|
NODE_ENV | production |
PORT | 3000 |
DATABASE_URL | (Paste Internal Database URL from Step 1) |
DB_SSL | true |
IS_CLOUD | true |
JWT_SECRET | (Enter a random secure secret string) |
- Click Create Web Service.
Environment Variables Reference
| Variable | Example / Default | Description |
|---|---|---|
NODE_ENV | production | Enables production mode and cloud safety protocols |
PORT | 3000 | Port assigned by Render for Express web service |
DATABASE_URL | postgresql://user:pass@dpg-xyz.render.com/retailsale_db | PostgreSQL Connection URI |
DB_SSL | true | Enables SSL encryption for cloud database queries |
IS_CLOUD | true | Explicitly declares cloud deployment environment |
JWT_SECRET | super-secret-jwt-key-2026 | Secret key used to sign authentication tokens |
Troubleshooting & FAQ
Q: The page shows 404 when I refresh a sub-route on the web app.
**A:**Ensure server.js has the SPA catch-all middleware active. server.js automatically redirects non-API GET requests back to index.html when backend/public/ exists.
Q: Does this break the Windows Desktop or Mobile offline apps?
A: **No.**Non-web platforms (Windows, macOS, Linux, Android, iOS) continue reading server_config.json and operating offline. The web configuration is strictly isolated inside if (kIsWeb) guards.
Q: Why is the first request slow on Render Free Tier?
**A:**Web services on Render's free tier automatically spin down after 15 minutes of inactivity. The first request after sleep will take 30-50 seconds to start up the container.
Documentation maintained for Retail POS project.