mock-fried 1.0.3 → 1.0.5

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/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "1.0.3",
7
+ "version": "1.0.5",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -1,4 +1,5 @@
1
- import { defineEventHandler, getQuery, readBody, createError } from "h3";
1
+ import { defineEventHandler, readBody, createError } from "h3";
2
+ import { parseQuery } from "ufo";
2
3
  import { useRuntimeConfig } from "#imports";
3
4
  import { readFileSync } from "node:fs";
4
5
  import yaml from "js-yaml";
@@ -291,11 +292,14 @@ export default defineEventHandler(async (event) => {
291
292
  const config = useRuntimeConfig(event);
292
293
  const mockConfig = config.mock;
293
294
  const prefix = mockConfig?.prefix || "/mock";
294
- let path = event.path;
295
+ const fullPath = event.path;
296
+ const queryIndex = fullPath.indexOf("?");
297
+ let path = queryIndex >= 0 ? fullPath.substring(0, queryIndex) : fullPath;
298
+ const queryString = queryIndex >= 0 ? fullPath.substring(queryIndex + 1) : "";
295
299
  if (path.startsWith(prefix)) {
296
300
  path = path.substring(prefix.length) || "/";
297
301
  }
298
- const query = getQuery(event);
302
+ const query = parseQuery(queryString);
299
303
  let body;
300
304
  if (event.method !== "GET" && event.method !== "HEAD") {
301
305
  try {
@@ -6,7 +6,17 @@ import { readFileSync, existsSync } from "node:fs";
6
6
  import yaml from "js-yaml";
7
7
  import { getClientPackage } from "../utils/client-parser.js";
8
8
  const logger = consola.withTag("mock-fried");
9
- const _require = createRequire(import.meta.url);
9
+ let _require = null;
10
+ function getRequire() {
11
+ if (!_require) {
12
+ try {
13
+ _require = createRequire(import.meta.url);
14
+ } catch {
15
+ _require = createRequire(process.cwd() + "/package.json");
16
+ }
17
+ }
18
+ return _require;
19
+ }
10
20
  function convertEndpointToPathItem(endpoint) {
11
21
  const parameters = [
12
22
  ...(endpoint.pathParams || []).map((p) => ({
@@ -50,7 +60,7 @@ function convertEndpointToPathItem(endpoint) {
50
60
  }
51
61
  function parseClientPackageSchema(config) {
52
62
  try {
53
- const packagePath = _require.resolve(`${config.package}/package.json`);
63
+ const packagePath = getRequire().resolve(`${config.package}/package.json`);
54
64
  const packageRoot = packagePath.replace("/package.json", "").replace("\\package.json", "");
55
65
  const clientPackage = getClientPackage(packageRoot, config);
56
66
  const apiGroups = /* @__PURE__ */ new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mock-fried",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Nuxt3 Mock API Module - OpenAPI & Protobuf RPC Mock Server",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,7 +60,8 @@
60
60
  "consola": "^3.4.2",
61
61
  "js-yaml": "^4.1.0",
62
62
  "openapi-backend": "^5.10.6",
63
- "pathe": "^2.0.2"
63
+ "pathe": "^2.0.2",
64
+ "ufo": "^1.6.1"
64
65
  },
65
66
  "devDependencies": {
66
67
  "@nuxt/devtools": "^3.1.1",