forked from Lilly-Protocol/lily-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-29-Lilly-Protocol-lily-frontend.ts
More file actions
37 lines (34 loc) · 1.04 KB
/
Copy pathgithub-29-Lilly-Protocol-lily-frontend.ts
File metadata and controls
37 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// src/mocks/browser.ts
import { setupWorker, rest } from 'msw';
import { environment } from '../environments/environment';
// Define mock handlers for API endpoints
const handlers = [
rest.get('/api/*', (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({ message: 'Mocked response', timestamp: Date.now() })
);
}),
rest.post('/api/*', (req, res, ctx) => {
return res(
ctx.status(201),
ctx.json({ message: 'Created', id: Math.random().toString(36).substr(2, 9) })
);
}),
rest.put('/api/*', (req, res, ctx) => {
return res(ctx.status(200), ctx.json({ message: 'Updated' }));
}),
rest.delete('/api/*', (req, res, ctx) => {
return res(ctx.status(204));
}),
];
// Create and export worker (browser-only)
export const worker = setupWorker(...handlers);
// Start worker in development/test environments
if (environment.name === 'development' || environment.name === 'test') {
worker.start({
serviceWorker: {
url: environment.mockServiceWorkerUrl || '/mockServiceWorker.js',
},
});
}