Demo Mode (Online Demo)
The online demo is the same frontend built with VITE_DEMO=1: no backend is contacted — src/demo/index.ts installs a custom axios adapter that answers every /api request with fake data. Any account/password logs in.
Build Entry
bash
VITE_DEMO=1 VITE_BASE=/gopherforge/ npm run buildmain.tsxdynamicallyimport('./demo')+installDemoAdapter()only whenVITE_DEMO === '1'— the branch is statically eliminated from normal builds.App.tsxrenders a "Demo mode · pure-frontend fake data" badge under demo mode.VITE_BASE=/gopherforge/is for the GitHub Pages sub-path deployment (thedeploy-demo.ymlworkflow); use/for localpreview.
The Adapter (src/demo/index.ts)
request.defaults.adapter = async (config) => ...takes over every request.- It keeps
routes: Array<[method, RegExp, handler]>and matches onmethod + URL regex; a hit returns constructed fake data. - Uncovered
GETendpoints return an empty list{ list: [], total: 0 }; write endpoints politely reject with400— so no page crashes, it's just empty.
Adding Fake Data for a New Page
Three steps (the recently added "monitoring alerts" example is a good reference):
- Menu row — add one to
menuRowslikemonitor-redis:
ts
{ id: 42, name: 'monitor-alerts', title: '告警管理', icon: 'alert',
path: '/monitor/alerts', component: 'monitor/alerts/index',
parent_id: 30, sort: 5, status: 1, hidden: 0, permission: 'system:alert:list' }- The
permissionfield is auto-collected into thepermissionsarray (demoUserholds all of them), so button-level permission works too. iconmust be a key present inMainLayout'sICON_MAP.
Data arrays — define fake data (e.g.
alertRules/alertEvents) covering several states/edges to look realistic; type multi-shaped arrays explicitly (seeDemoAlertRule).Route entries — register in
routesby method + URL regex;GETusespaged(list, query):
ts
['get', /^\/api\/v1\/monitor\/alert-rules$/, (_m, _b, q) => paged(alertRules, q)],
['post', /^\/api\/v1\/monitor\/alert-rules$/, (_m, body) => { /* unshift fake record */ }],
['delete', /^\/api\/v1\/monitor\/alert-rules\/(\d+)$/, (m) => { /* splice */ }],Prerequisite: the page must already exist in the real route table (src/router/index.tsx) — demo only provides data; routes and pages are shared.
Verification
bash
VITE_DEMO=1 npm run build && npm run preview # open the page and check fake data renders
npm run lint # don't forget lint