file
This commit is contained in:
+2
-1
@@ -27,6 +27,7 @@ export function mockPlugin(globalMock = false): Plugin {
|
||||
const requestUrl = new URL(req.url, 'http://localhost')
|
||||
void (async () => {
|
||||
const raw = req.method === 'GET' ? '' : await readBody(req)
|
||||
const isJsonBody = (req.headers['content-type'] ?? '').includes('application/json')
|
||||
const rule = mockRules.find(
|
||||
(item) =>
|
||||
item.method === (req.method ?? 'GET').toUpperCase() &&
|
||||
@@ -41,7 +42,7 @@ export function mockPlugin(globalMock = false): Plugin {
|
||||
url: requestUrl.pathname,
|
||||
params: matched ? matched.slice(1) : [],
|
||||
query: Object.fromEntries(requestUrl.searchParams.entries()),
|
||||
body: raw ? JSON.parse(raw) : {},
|
||||
body: raw && isJsonBody ? JSON.parse(raw) : {},
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||
|
||||
Reference in New Issue
Block a user