File tree Expand file tree Collapse file tree 4 files changed +76
-3
lines changed
Expand file tree Collapse file tree 4 files changed +76
-3
lines changed Original file line number Diff line number Diff line change 1+ name : Deploy Mock (GitHub Pages)
2+
3+ on :
4+ push :
5+ branches : ["main"]
6+ workflow_dispatch : {}
7+
8+ permissions :
9+ contents : read
10+ pages : write
11+ id-token : write
12+
13+ concurrency :
14+ group : pages
15+ cancel-in-progress : true
16+
17+ jobs :
18+ build :
19+ runs-on : ubuntu-latest
20+ steps :
21+ - uses : actions/checkout@v4
22+ - uses : pnpm/action-setup@v4
23+ with :
24+ version : 9
25+ - uses : actions/setup-node@v4
26+ with :
27+ node-version : 20
28+ cache : pnpm
29+ - run : pnpm install --frozen-lockfile
30+ - run : pnpm build -- --base="/${{ github.event.repository.name }}/"
31+ env :
32+ VITE_USE_MOCKS : " true"
33+ VITE_API_BASE_URL : " /${{ github.event.repository.name }}/api/v1/admin"
34+ - uses : actions/upload-pages-artifact@v3
35+ with :
36+ path : dist
37+
38+ deploy :
39+ needs : build
40+ runs-on : ubuntu-latest
41+ environment :
42+ name : github-pages
43+ url : ${{ steps.deployment.outputs.page_url }}
44+ steps :
45+ - id : deployment
46+ uses : actions/deploy-pages@v4
47+
Original file line number Diff line number Diff line change @@ -182,6 +182,26 @@ e-commerce-dashboard/
1821822 . ` ?mock=1 `
1831833 . ` localStorage.USE_MOCKS === "1" `
184184
185+ ## Deploy Mock (Static)
186+
187+ This repo can be deployed as a fully-static “mock” dashboard (no backend) using MSW.
188+
189+ ### GitHub Pages (automatic)
190+
191+ 1 . In GitHub, open ** Settings → Pages** and set ** Build and deployment** to ** GitHub Actions** .
192+ 2 . Push to ` main ` (or run the workflow manually).
193+
194+ Workflow: ` .github/workflows/pages-mock.yml ` .
195+
196+ ### Vercel (automatic)
197+
198+ 1 . Import the repo in Vercel (Framework preset: Vite).
199+ 2 . Set environment variables:
200+ - ` VITE_USE_MOCKS=true `
201+ - (optional) ` VITE_API_BASE_URL=/api/v1/admin `
202+ 3 . Build command: ` pnpm build ` (or ` npm run build ` )
203+ 4 . Output directory: ` dist `
204+
185205## API Documentation
186206
187207- OpenAPI YAML: ` docs/swagger.yaml `
Original file line number Diff line number Diff line change @@ -61,11 +61,16 @@ import type {
6161import { QueryParams , buildQueryParams , validateQueryParams } from './queryBuilder' ;
6262import { transformResponse } from './transformers' ;
6363import type { ErrorResponse } from '@/types/api' ;
64+ import { shouldEnableMocks } from '@/mocks/config' ;
6465
6566// Accepts plain objects (typed form values) or FormData payloads
6667type UnknownRecord = Record < string , unknown > | FormData ;
6768
68- const API_BASE_URL = import . meta. env . VITE_API_BASE_URL || 'http://localhost:3000/api/v1/admin' ;
69+ const API_BASE_URL =
70+ import . meta. env . VITE_API_BASE_URL ||
71+ ( shouldEnableMocks ( )
72+ ? `${ import . meta. env . BASE_URL } api/v1/admin`
73+ : 'http://localhost:3000/api/v1/admin' ) ;
6974
7075const api = axios . create ( {
7176 baseURL : API_BASE_URL ,
Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ export async function startMockWorker() {
88 if ( ! config . enabled ) return ;
99
1010 const apiBaseUrl =
11- import . meta. env . VITE_API_BASE_URL ?? "http://localhost:3000/api/v1/admin" ;
11+ import . meta. env . VITE_API_BASE_URL ??
12+ `${ import . meta. env . BASE_URL } api/v1/admin` ;
1213 const handlers = createHandlers ( {
1314 spec : mockSpec ,
1415 apiBaseUrl,
@@ -23,7 +24,7 @@ export async function startMockWorker() {
2324
2425 await worker . start ( {
2526 onUnhandledRequest : "bypass" ,
26- serviceWorker : { url : "/ mockServiceWorker.js" } ,
27+ serviceWorker : { url : ` ${ import . meta . env . BASE_URL } mockServiceWorker.js` } ,
2728 // Ensure the worker is ready before continuing
2829 quiet : false ,
2930 } ) ;
You can’t perform that action at this time.
0 commit comments