vite-plugin-mock-dev-server 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -52,7 +52,7 @@ var import_vite = require("vite");
52
52
 
53
53
  // package.json
54
54
  var name = "vite-plugin-mock-dev-server";
55
- var version = "0.4.0";
55
+ var version = "0.4.1";
56
56
 
57
57
  // src/esbuildPlugin.ts
58
58
  var import_promises = __toESM(require("fs/promises"), 1);
@@ -324,21 +324,22 @@ var import_path_to_regexp = require("path-to-regexp");
324
324
  var import_co_body = __toESM(require("co-body"), 1);
325
325
  var import_formidable = __toESM(require("formidable"), 1);
326
326
  async function parseReqBody(req, options) {
327
+ var _a;
327
328
  const method = req.method.toUpperCase();
328
329
  if (["GET", "DELETE", "HEAD"].includes(method))
329
330
  return void 0;
330
- const type = req.headers["content-type"];
331
+ const type = ((_a = req.headers["content-type"]) == null ? void 0 : _a.toLocaleLowerCase()) || "";
331
332
  try {
332
- if (type === "application/json") {
333
+ if (type.startsWith("application/json")) {
333
334
  return await import_co_body.default.json(req);
334
335
  }
335
- if (type === "application/x-www-form-urlencoded") {
336
+ if (type.startsWith("application/x-www-form-urlencoded")) {
336
337
  return await import_co_body.default.form(req);
337
338
  }
338
- if (type === "text/plain") {
339
+ if (type.startsWith("text/plain")) {
339
340
  return await import_co_body.default.text(req);
340
341
  }
341
- if (type == null ? void 0 : type.startsWith("multipart/form-data;")) {
342
+ if (type.startsWith("multipart/form-data")) {
342
343
  return await parseMultipart(req, options);
343
344
  }
344
345
  } catch (e) {
@@ -435,6 +436,7 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
435
436
  req.refererQuery = refererQuery;
436
437
  req.params = params;
437
438
  res.setHeader("Content-Type", "application/json");
439
+ res.setHeader("Cache-Control", "no-cache,max-age=0");
438
440
  res.setHeader("X-Mock", "generate by vite:mock-dev-server");
439
441
  if (currentMock.headers) {
440
442
  const headers = isFunction(currentMock.headers) ? await currentMock.headers({
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { createFilter } from "vite";
9
9
 
10
10
  // package.json
11
11
  var name = "vite-plugin-mock-dev-server";
12
- var version = "0.4.0";
12
+ var version = "0.4.1";
13
13
 
14
14
  // src/esbuildPlugin.ts
15
15
  import fsp from "fs/promises";
@@ -281,21 +281,22 @@ import { match, pathToRegexp } from "path-to-regexp";
281
281
  import bodyParser from "co-body";
282
282
  import formidable from "formidable";
283
283
  async function parseReqBody(req, options) {
284
+ var _a;
284
285
  const method = req.method.toUpperCase();
285
286
  if (["GET", "DELETE", "HEAD"].includes(method))
286
287
  return void 0;
287
- const type = req.headers["content-type"];
288
+ const type = ((_a = req.headers["content-type"]) == null ? void 0 : _a.toLocaleLowerCase()) || "";
288
289
  try {
289
- if (type === "application/json") {
290
+ if (type.startsWith("application/json")) {
290
291
  return await bodyParser.json(req);
291
292
  }
292
- if (type === "application/x-www-form-urlencoded") {
293
+ if (type.startsWith("application/x-www-form-urlencoded")) {
293
294
  return await bodyParser.form(req);
294
295
  }
295
- if (type === "text/plain") {
296
+ if (type.startsWith("text/plain")) {
296
297
  return await bodyParser.text(req);
297
298
  }
298
- if (type == null ? void 0 : type.startsWith("multipart/form-data;")) {
299
+ if (type.startsWith("multipart/form-data")) {
299
300
  return await parseMultipart(req, options);
300
301
  }
301
302
  } catch (e) {
@@ -392,6 +393,7 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
392
393
  req.refererQuery = refererQuery;
393
394
  req.params = params;
394
395
  res.setHeader("Content-Type", "application/json");
396
+ res.setHeader("Cache-Control", "no-cache,max-age=0");
395
397
  res.setHeader("X-Mock", "generate by vite:mock-dev-server");
396
398
  if (currentMock.headers) {
397
399
  const headers = isFunction(currentMock.headers) ? await currentMock.headers({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-mock-dev-server",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "keywords": [
5
5
  "vite",
6
6
  "plugin",