vite-plugin-mock-dev-server
Advanced tools
Comparing version 0.3.9 to 0.3.10
@@ -290,2 +290,3 @@ // src/mockMiddleware.ts | ||
import bodyParser from "co-body"; | ||
import formidable from "formidable"; | ||
async function parseReqBody(req) { | ||
@@ -305,4 +306,20 @@ const method = req.method.toUpperCase(); | ||
} | ||
if (type == null ? void 0 : type.startsWith("multipart/form-data;")) { | ||
return await parseMultipart(req); | ||
} | ||
return void 0; | ||
} | ||
async function parseMultipart(req) { | ||
const form = formidable({ multiples: true }); | ||
debug("multiparty start"); | ||
return new Promise((resolve, reject) => { | ||
form.parse(req, (error, fields, files) => { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
resolve({ ...fields, ...files }); | ||
}); | ||
}); | ||
} | ||
@@ -309,0 +326,0 @@ // src/validator.ts |
{ | ||
"name": "vite-plugin-mock-dev-server", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"keywords": [ | ||
@@ -52,2 +52,3 @@ "vite", | ||
"fast-glob": "^3.2.12", | ||
"formidable": "^2.1.1", | ||
"json5": "^2.2.2", | ||
@@ -61,2 +62,3 @@ "path-to-regexp": "^6.2.1" | ||
"@types/debug": "^4.1.7", | ||
"@types/formidable": "^2.0.5", | ||
"@types/node": "^18.11.7", | ||
@@ -63,0 +65,0 @@ "bumpp": "^8.2.1", |
@@ -36,3 +36,3 @@ # vite-plugin-mock-dev-server | ||
- 🍕 Support `viteConfig.define` in mock file | ||
- 📤 Support `multipart` content-type,mock upload file. | ||
## Documentation | ||
@@ -39,0 +39,0 @@ |
@@ -37,2 +37,3 @@ # vite-plugin-mock-dev-server | ||
- 🍕 支持在 mock文件中使用 `viteConfig.define`配置字段 | ||
- 📤 支持 multipart 类型,模拟文件上传 | ||
@@ -39,0 +40,0 @@ |
Sorry, the diff of this file is not supported yet
91183
1101
10
16
+ Addedformidable@^2.1.1
+ Addedasap@2.0.6(transitive)
+ Addeddezalgo@1.0.4(transitive)
+ Addedformidable@2.1.2(transitive)
+ Addedhexoid@1.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedwrappy@1.0.2(transitive)