mirror of
https://github.com/morten-olsen/http.md.git
synced 2026-02-08 00:46:28 +01:00
26 lines
616 B
TypeScript
26 lines
616 B
TypeScript
import { http, HttpResponse } from 'msw';
|
|
|
|
export const handlers = [
|
|
http.all('https://httpbin.org/*', async (req) => {
|
|
const bodyRaw = await req.request.text();
|
|
let bodyJson: unknown = undefined;
|
|
try {
|
|
bodyJson = JSON.parse(bodyRaw);
|
|
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
} catch (e) {
|
|
// Ignore error
|
|
}
|
|
return HttpResponse.text(
|
|
JSON.stringify(
|
|
{
|
|
headers: Object.fromEntries(req.request.headers.entries()),
|
|
data: bodyRaw,
|
|
json: bodyJson,
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
}),
|
|
];
|