doesitarm/test/msw/handlers.js
2023-08-12 16:14:17 -05:00

15 lines
No EOL
401 B
JavaScript

import path from 'node:path'
import fs from 'fs/promises'
import { rest } from 'msw'
export const handlers = [
rest.get('https://mock.msw/*', async (req, res, ctx) => {
const { endpoint } = req.params;
const urlPath = req.url.pathname
const fileContent = await fs.readFile( `./static/${urlPath}`, 'utf8')
return res(ctx.json(JSON.parse(fileContent)))
}),
];