¥69.90
One-time template price with installation and customization
One-click private deployment after purchase, details Live previewDeployment Guide
This is the deployment manual for CouponCraft (coupon campaign tool, v1.2.0). The whole system is one container on one port: admin UI, API, mobile claim page and uploaded files all answer on 8080. There is no separate Nginx container and no external database to provision.
- Image base:
oven/bun:1.4— runtime only, nothing is installed or built inside the container - Port: 8080 (fixed inside the container; the host mapping is yours to change)
- Data:
/app/data—sqlite.dbplusuploads/. Mount a volume here - Health check:
GET /api/health - Runtime API mode:
/config.js, served by the API from environment variables, defaulthttp
1. Five-minute deploy
Option A — docker compose (recommended)
# 1. Unpack (the unpacked directory is the build context)
unzip couponcraft-platform-upload.zip -d couponcraft && cd couponcraft
# 2. Decide three things before going live (defaults are only safe for a local trial)
export JWT_SECRET="$(head -c 48 /dev/urandom | base64)"
export SUPER_ADMIN_EMAIL="owner@yourcompany.com"
export SUPER_ADMIN_PASSWORD="a strong password of your own"
export DEMO_SEED=false # no demo business data
# 3. Start (the first run builds the image)
docker compose up -d --build
# 4. Check health
curl -s http://127.0.0.1:8080/api/health
Open http://<server-ip>:8080, sign in with SUPER_ADMIN_EMAIL / SUPER_ADMIN_PASSWORD, change the password when prompted (first sign-in always forces it), and you are in.
Option B — docker run
docker build -t couponcraft:1.2.0 .
docker run -d --name couponcraft \
-p 8080:8080 \
-v couponcraft-data:/app/data \
-e JWT_SECRET="$(head -c 48 /dev/urandom | base64)" \
-e SUPER_ADMIN_EMAIL="owner@yourcompany.com" \
-e SUPER_ADMIN_PASSWORD="a strong password of your own" \
-e DEMO_SEED=false \
--restart unless-stopped \
couponcraft:1.2.0
Option C — platform one-click
intematrix.deploy.json already declares everything the platform needs: mode=single, one container named app, port 8080, health check on /api/health, and 0.5 CPU / 1 GB memory / 20 GB storage.
First-60-seconds checklist
| Check | Command / action | Expected |
|---|---|---|
| Process alive | curl -s http://IP:8080/api/health |
{"status":"ok",...,"features":[...]} |
| Front end served | Open / in a browser |
Landing page, not a blank screen |
| API mode correct | curl -s http://IP:8080/config.js |
window.__IMX_CONFIG__ = {"apiMode":"http","apiBase":"/api"} |
| Data persisted | docker exec couponcraft ls -l /app/data |
sqlite.db and uploads/ present |
| Sign-in works | Sign in as the owner | Change-password page (first time) or the workspace |
| Demo data off | Console → Coupons | Empty list (correct with DEMO_SEED=false) |
2. What the container does
| Job | Implementation | Paths |
|---|---|---|
| API | ElysiaJS, mounted under /api |
/api/** |
| Static front end | In production the API serves the built assets in PUBLIC_DIR |
/, /assets/**, static /config.js fallback, /favicon.svg |
| Uploaded files | An explicit route at the site root, registered before static serving | /upload/YYYY/MM/DD/<uuid>.<ext> |
The front end uses a HashRouter (routes live in the #/admin/... fragment), so the server needs no history fallback — returning index.html for / is enough. Both / and /config.js are served with cache-control: no-store so a redeploy never leaves a stale shell or a stale config in the browser.
Inside the container:
/app/server/index.js backend bundle (this is what CMD runs)
/app/public/ front-end build (index.html, assets, config.js, .build-meta.json)
/app/drizzle/ SQL migrations, executed automatically on start
/app/data/sqlite.db database (volume)
/app/data/uploads/ uploaded files (volume)
3. How the front end talks to the API: /config.js
The front end loads /config.js before the app bundle and decides from it whether to call the real API or fall back to bundled demo data:
// what the front end reads
window.__IMX_CONFIG__ = { apiMode: "http", apiBase: "/api" };
Three sources, in priority order:
- Production deployment. Inside the container
GET /config.jsis intercepted by the API and generated on the fly from environment variables:PUBLIC_API_MODE— defaults tohttp; only an explicitmockswitches to demo modePUBLIC_API_BASE— defaults to/api- The response is
no-store, so changing an environment variable and restarting the container is enough; no rebuild needed
- Platform online preview. The preview service injects a mock
/config.js, so the same build is clickable without a backend. Preview only — never used for deployment. - Static fallback.
apps/web/dist/config.jsships with the build (http+/api) and only matters when the files are hosted without the API.
Why not probe /api/health to guess the mode? The old approach misread a healthy backend as demo mode when a single probe timed out, and the page then showed sample data forever. Now the mode has three explicit sources: when something looks wrong, curl /config.js tells you which one won.
Rule of thumb: seeing demo data in the UI → check /config.js first. If it says mock, look at environment variables and proxy caching. Only if it says http is the problem in the API.
4. Environment variables
4.1 The ones that matter
| Variable | Default | Notes |
|---|---|---|
PORT |
8080 (in container) |
Listener inside the container. Do not change unless you also change EXPOSE and the health check |
BIND_HOST |
0.0.0.0 |
Must stay 0.0.0.0 in a container; 127.0.0.1 makes the service unreachable from the host |
JWT_SECRET |
dev-secret-change-me |
Token signing key. Replace with a strong random value in production; changing it signs everyone out |
SUPER_ADMIN_EMAIL |
admin@example.com |
Owner account, created on first start |
SUPER_ADMIN_NAME |
林小满(店主) |
Owner display name |
SUPER_ADMIN_PASSWORD |
Admin@123456 |
Owner initial password. First sign-in forces a change; in production an existing account with the same email is not overwritten |
DEMO_SEED |
true |
Whether to seed demo business data (stores, members, coupons, codes, redemptions…). Set false before going live; note that it does not remove the demo member accounts (see Product Spec §5) |
PUBLIC_API_MODE |
http |
Value emitted in /config.js. Only mock turns on demo mode |
PUBLIC_API_BASE |
/api |
API base emitted in /config.js. Use a full URL when the API lives on another domain, e.g. https://api.example.com/api |
CORS_ORIGIN |
* |
Allowed origins. Narrow it to your domain when front end and API are split |
4.2 Data and storage
| Variable | Default | Notes |
|---|---|---|
DB_DRIVER |
sqlite |
sqlite / mysql / postgres. Only sqlite has been tested |
DATABASE_URL |
/app/data/sqlite.db |
File path for sqlite, connection string for mysql/pg |
UPLOAD_DIR |
/app/data/uploads |
Must live on the mounted volume |
PUBLIC_DIR |
/app/public |
Front-end build directory |
MIGRATIONS_DIR |
/app/drizzle |
SQL migrations, applied on start |
STORAGE_DRIVER |
local |
s3 and oss are placeholders; object storage is not wired |
4.3 Runtime and logging
| Variable | Default | Notes |
|---|---|---|
NODE_ENV |
development |
Must be production in deployment, otherwise static serving is off |
LOG_LEVEL |
info |
debug / info / warn / error |
RATE_LIMIT_LOGIN_PER_MINUTE |
30 |
Sign-in attempts per IP per minute; <=0 disables. Counters live in process memory |
WS_TICKET_TTL_SEC |
60 |
WebSocket one-time ticket lifetime in seconds |
AI_CONFIG_SECRET |
empty | Only needed if you store model keys in the console's AI settings (AES-256-GCM passphrase). Replacing it makes stored keys undecryptable |
MAIL_PROVIDER / MAIL_FROM / SMS_PROVIDER |
console / no-reply@example.com / console |
Message drivers. console writes to logs; smtp / ses / aliyun / twilio are placeholders |
Environment variables are for deployment concerns (port, secrets, accounts, database location). Business constants — approval threshold, redemption cap, code length — live in the console's Settings page, are stored in the database, and apply immediately.
5. Local development
# dependencies (Bun 1.4+)
bun install
# front end (5173) and API (3000) together
bun run dev
# one at a time
bun run dev:api
bun run dev:web
Local ports differ from the container: 5173 (front end) + 3000 (API); 8080 is container-only. Vite proxies /api (and /upload) to http://127.0.0.1:3000. If the API runs elsewhere, set VITE_API_PROXY (or API_PORT) and restart Vite.
Three front-end modes:
| Command | Mode | Use |
|---|---|---|
bun run dev |
mock |
Bundled demo data, no backend needed |
bun run dev:http |
http |
Real API — the normal development mode |
bun run dev:mock |
mock |
Force demo data |
Handy gates:
bun run check # design tokens, i18n, permission annotations, types
bun run check:i18n # dictionaries only
bun run check:perm # every write endpoint must declare a permission code
bun run test # backend e2e: sign-in, cross-role 403, coupon flows, system config
bun run build # production build (http front end + backend bundle)
bun run check:dist # asserts dist is apiMode=http
To try the production shape locally, use bun run serve:dist, or simply build the container.
6. Data and backups
6.1 Where the data is
| Content | Path | Notes |
|---|---|---|
| Database | /app/data/sqlite.db |
Single SQLite file; -wal and -shm may accompany it |
| Uploads | /app/data/uploads/YYYY/MM/DD/ |
Card images, banners; public URLs are /upload/... |
| Migrations | /app/drizzle/ |
Updated with the image, applied on start |
6.2 Backing up
# Option 1: back up the whole volume (recommended — database and uploads together)
docker run --rm -v couponcraft-data:/data -v "$PWD":/backup alpine \
tar czf /backup/couponcraft-$(date +%F).tar.gz -C /data .
# Option 2: copy just the database (checkpoint WAL first for a consistent snapshot)
docker exec couponcraft bun -e 'import {Database} from "bun:sqlite"; new Database("/app/data/sqlite.db").exec("PRAGMA wal_checkpoint(TRUNCATE)")'
docker cp couponcraft:/app/data/sqlite.db ./sqlite-$(date +%F).db
When to back up: before every campaign launch, after a bulk distribution, and always before an upgrade.
Restoring (order matters, otherwise you can restore a half-written transaction):
docker compose stop # 1. stop the container
# 2. replace /app/data with the backup (whole volume, or sqlite.db + uploads)
docker compose start # 3. start; migrations run automatically
curl -s http://127.0.0.1:8080/api/health
6.3 Reconciliation exports
The app deliberately does not offer a "one-click database backup" — copying a SQLite file from a running container risks a torn read and desynchronises the database from the uploads. For reconciliation, use Console → System settings → Backup & export to download three CSVs: coupons, claims, redemptions. Use the code as the join key.
7. Reverse proxy and HTTPS
Recommended shape: a single domain, https://coupon.example.com proxying to 127.0.0.1:8080, no sub-path.
server {
listen 443 ssl http2;
server_name coupon.example.com;
ssl_certificate /etc/letsencrypt/live/coupon.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/coupon.example.com/privkey.pem;
# keep this at or above the console's upload size limit (default 100 MB)
client_max_body_size 100m;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket (/api/ws)
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 3600s;
}
# never cache the runtime config or the entry document
# (`= /` is an exact match and wins over the `location /` above)
location = /config.js { proxy_pass http://127.0.0.1:8080; add_header Cache-Control "no-store"; }
location = / { proxy_pass http://127.0.0.1:8080; add_header Cache-Control "no-store"; }
}
Notes:
- Do not cache
/config.jsor/. A cached copy produces the classic "deployed successfully but the page still shows demo data / the old version". - Pass
X-Forwarded-For. Without it, every IP in the operation and login logs is the proxy address and you cannot tell who did what. - Raise
client_max_body_size. If it is below the upload limit, large images fail with 413. - Terminate TLS at the proxy. The container keeps speaking HTTP; set
CORS_ORIGINtohttps://coupon.example.comif you need it. - Before exposing to the internet, consider restricting
/docs(the built-in Swagger UI) and/api/monitorat the proxy./docsis convenient for integration work and unnecessary in public.
If you must split into two domains (coupon.example.com and api.example.com), change three things: PUBLIC_API_BASE=https://api.example.com/api, CORS_ORIGIN=https://coupon.example.com, and VITE_WS_URL=wss://api.example.com/api/ws — the last one is a build-time variable, so the front end must be rebuilt.
8. Upgrades
The data volume is decoupled from the image, so upgrading means replacing the image:
# 1. back up (see §6)
# 2. pull the new package / image and rebuild the container (the volume stays)
docker compose down # do NOT add -v, that deletes the volume
docker compose up -d --build
# 3. verify
curl -s http://127.0.0.1:8080/api/health # the version field should change
- Migrations in
/app/drizzlerun automatically on start (idempotently); there is no SQL to apply by hand. - If the page still looks old after an upgrade, hard-refresh (
Ctrl+F5) to rule out the browser, then check whether the proxy caches/. - To roll back, keep the previous image tag,
docker compose down, then rebuild from the old image. If the new version changed the schema, restore the pre-upgrade backup as well.
9. Troubleshooting
| Symptom | Most likely cause | What to do |
|---|---|---|
| "Demo data" banner never goes away | /config.js returns apiMode: "mock", or a proxy/CDN cached it |
curl -s http://IP:8080/config.js; make sure PUBLIC_API_MODE is not mock; purge the proxy cache |
| Blank page or 404 everywhere | Wrong PUBLIC_DIR, or apps/web/dist missing from the image |
docker exec -it couponcraft ls /app/public; rebuild with bun run build (http), not build:mock |
| The old version keeps loading | Browser or proxy cached index.html |
Hard-refresh; make sure / is no-store at the proxy |
| "Email or password is wrong" | Wrong password, or the account already exists so SUPER_ADMIN_PASSWORD is not applied |
Sign in with the old password and change it; or stop the container, back up, delete the row in users, start again |
| Stuck on the change-password page | mustChangePassword=true (first sign-in or after an admin reset) |
Expected — change the password. If it is forgotten, the owner must reset it |
| API returns 403 | The role lacks that permission code (e.g. a cashier calling the coupon-create endpoint) | Check the matrix in the Permissions Guide; switch account or role |
| API 404 for an endpoint you can see in the code | The container runs an old backend | curl /api/health and look for the capability name in features: absent means an old backend |
| Upload returns 413 | Proxy body limit below the upload limit | Raise client_max_body_size or lower the console's upload limit |
| Upload succeeds but the image 404s | /upload/* not proxied, or UPLOAD_DIR outside the volume |
Hit http://IP:8080/upload/... directly to rule out the proxy; check the volume |
| All data gone after a restart | /app/data was not mounted |
Run with -v couponcraft-data:/app/data; only a volume persists |
| Health check stays unhealthy | Startup failure (migration, port, file permissions) | docker logs couponcraft --tail 100; a common cause is /app/data not being writable by the container user |
| Garbled Chinese file names or documents | The zip was produced by a GBK tool | Repack with bun run pack:upload (it writes the UTF-8 flag) |
| Port 8080 already in use | Another service on the host | Pick another host port: set PORT in docker compose (the container keeps 8080), or change only the left-hand side of -p for docker run |
| Claim page blank on a phone | Wrong coupon id, or the coupon is not running | /h5/claim?coupon=<id>; the coupon must be active |
10. Packaging for upload / delivery
bun install
bun run check && bun run test # gates (optional but recommended)
bun run build # http front end + backend bundle
bun run check:dist # must report apiMode=http
bun run pack:upload # → couponcraft-platform-upload.zip (written next to the project dir)
The pack script does three things: copies into a staging directory, removes "ignore everything" .gitignore files and the artifact-ignore lines (otherwise the upload validator flags dist/out as content that should not be uploaded), then zips with Python's zipfile and verifies the UTF-8 flag on non-ASCII names. (Using the platform tar writes names in GBK and the distribution unpacker turns Chinese paths into mojibake.)
In the package: apps/web/dist, apps/api/out, apps/api/drizzle, docs/ (buyer documentation), the source, Dockerfile, docker-compose.yml, intematrix.deploy.json.
Not in the package: node_modules, data/ (local database and uploads), logs and temporary artifacts.
Limits: ZIP ≤ 128 MB, unpacked ≤ 512 MB, ≤ 10,000 files.
11. Redeploying after customisation
# 1. gates after your changes
bun run check && bun run test
# 2. rebuild artifacts (order matters: backend bundle, then front end)
bun run build
bun run check:dist
# 3. rebuild the container (volume preserved)
docker compose up -d --build
Three things people forget:
- Front-end changes need
bun run build. The container servesapps/web/dist; editing source changes nothing until you rebuild. - Backend changes need
bun run buildtoo. The container runsapps/api/out/index.js, notsrc. - Schema changes need migrations. Update all three dialect schemas and
apps/api/drizzle/**, otherwise an existing database will be missing columns.
12. Domain conventions
| Item | Convention |
|---|---|
| Recommended | One domain, one port: https://coupon.example.com → 127.0.0.1:8080 |
| Not recommended | Sub-path mounting (https://example.com/coupon/) — /api and /upload are absolute site-root paths; a sub-path means changing PUBLIC_API_BASE, the proxy rules and every printed QR link, and it is easy to miss one |
| Allowed | Split domains (coupon.example.com + api.example.com) with the three changes in §7 |
| Claim page | Same domain as the console: https://coupon.example.com/#/h5/claim?coupon=<id> — this is the URL encoded into store QR codes |
| Uploaded files | Relative /upload/... links on the same domain; a separate file domain only makes sense once uploads move to object storage |
| Tokens | Sent as Authorization: Bearer, never as cookies, so there is no cross-site cookie setup |
13. Health check as proof: GET /api/health
curl -s http://IP:8080/api/health
{
"status": "ok",
"service": "api",
"version": "1.2.0",
"features": ["auth.login", "auth.me", "coupons.list", "coupons.create", "redemption.redeem", "public.claim", "..."],
"startedAt": "2026-01-01T00:00:00.000Z",
"timestamp": "2026-01-01T00:05:00.000Z"
}
features is a capability inventory, not just a liveness flag: auth.* (sign-in, change password, sign-out), users.*, coupons.* (list, detail, create, update, actions, codes, extend, claims), base.* (stores, members, products, templates, batches, blacklist, exceptions, parameters), redemption.* (redeem, reverse, abnormal, records, pending), dashboard.*, public.* (claim page, claim, wallet), logs.*, monitor, files, ws.*.
How to use it when debugging — faster than reading code:
- An endpoint returns 404. Look for its capability name in
features. Absent → the container runs an old backend; rebuild the image, do not touch the code. Present but still 404 → now it is a routing or code problem. - The platform health check (
docker-compose.ymlandintematrix.deploy.jsonboth point at/api/health) only looks at HTTP 200, which is why this endpoint must stay dependency-free — it currently returns from memory without touching the database.
Frequently asked questions
- What do I get after purchase?
- The full source code (web frontend + API backend), deployment documentation and an online preview. After purchase you can download it from "My Projects" and use it for your own product.
- Can it be deployed to my own server?
- The Web + API edition supports one-click private deployment, so data stays on your own infrastructure. Mini-program and App add-on packages are not one-click deployable.
- Can I get a refund?
- Orders whose code package has not been downloaded can request a refund through a support ticket. Once the code package has been downloaded, refunds are not supported.
- How do I reach support?
- Open "My Projects" and click "Support" to submit a ticket. Staff reply inside the ticket, and status changes are pushed as WeChat notifications.
