From abe1c07a2abb4b98c37a34725e4917caafe6dc7e Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Wed, 18 Jan 2023 22:14:12 +0800 Subject: [PATCH] fix: use originalUrl to check mock call function request (#149) --- app/middleware/cluster_app_mock.js | 4 ++-- index.d.ts | 2 +- lib/mock_agent.js | 2 +- lib/request_call_function.js | 4 +--- package.json | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/middleware/cluster_app_mock.js b/app/middleware/cluster_app_mock.js index 5f1d7b4..35c2393 100644 --- a/app/middleware/cluster_app_mock.js +++ b/app/middleware/cluster_app_mock.js @@ -4,8 +4,8 @@ const co = require('co'); module.exports = () => { return function clusterAppMock(ctx, next) { - if (ctx.path !== '/__egg_mock_call_function') return next(); - + // use originalUrl to make sure other middlewares can't change request url + if (ctx.originalUrl !== '/__egg_mock_call_function') return next(); debug('%s %s, body: %j', ctx.method, ctx.url, ctx.request.body); const { method, property, args, needResult } = ctx.request.body; if (!method) { diff --git a/index.d.ts b/index.d.ts index ae82a8a..359ecce 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,7 +1,7 @@ import { Application, Context, EggLogger } from 'egg'; import { MockMate } from 'mm'; import { Test } from 'supertest'; -import { MockAgent } from 'urllib-next'; +import { MockAgent } from 'urllib'; export { MockAgent }; interface EggTest extends Test { diff --git a/lib/mock_agent.js b/lib/mock_agent.js index 1a9b5da..f5e6858 100644 --- a/lib/mock_agent.js +++ b/lib/mock_agent.js @@ -1,4 +1,4 @@ -const { MockAgent, setGlobalDispatcher, getGlobalDispatcher } = require('urllib-next'); +const { MockAgent, setGlobalDispatcher, getGlobalDispatcher } = require('urllib'); let _mockAgent; let _global; diff --git a/lib/request_call_function.js b/lib/request_call_function.js index abf3583..6f6bf83 100644 --- a/lib/request_call_function.js +++ b/lib/request_call_function.js @@ -1,6 +1,4 @@ -'use strict'; - -const httpclient = require('urllib-next'); +const httpclient = require('urllib'); const { port, method, args, property, needResult } = JSON.parse(process.argv[2]); const url = `http://127.0.0.1:${port}/__egg_mock_call_function`; diff --git a/package.json b/package.json index 1b576eb..f6cad47 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "mm": "^3.0.2", "sdk-base": "^3.0.1", "supertest": "^6.2.4", - "urllib-next": "^3.2.3" + "urllib": "^3.10.1" }, "peerDependencies": { "egg": "^3.12.0",