mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-18 15:20:25 +08:00
feat: 增强 mockServer
This commit is contained in:
parent
bc88d44350
commit
333be5069f
@ -103,7 +103,11 @@ module.exports = function(){
|
||||
header: context.ctx.header,
|
||||
query: context.ctx.query,
|
||||
body: context.ctx.request.body,
|
||||
mockJson: context.mockJson
|
||||
mockJson: context.mockJson,
|
||||
params: Object.assign({}, context.ctx.query, context.ctx.request.body),
|
||||
resHeader: context.resHeader,
|
||||
httpCode: context.httpCode,
|
||||
delay: context.httpCode
|
||||
}
|
||||
sandbox.cookie = {};
|
||||
|
||||
@ -112,6 +116,16 @@ module.exports = function(){
|
||||
sandbox.cookie[ parts[ 0 ].trim() ] = ( parts[ 1 ] || '' ).trim();
|
||||
});
|
||||
sandbox = yapi.commons.sandbox(sandbox, script);
|
||||
sandbox.delay = isNaN(sandbox.delay) ? 0 : +sandbox.delay;
|
||||
let handleMock = new Promise(resolve=>{
|
||||
setTimeout(()=>{
|
||||
resolve(true)
|
||||
}, sandbox.delay)
|
||||
})
|
||||
await handleMock;
|
||||
context.mockJson = sandbox.mockJson;
|
||||
context.resHeader = sandbox.resHeader;
|
||||
context.httpCode = sandbox.httpCode;
|
||||
context.delay = sandbox.delay;
|
||||
})
|
||||
}
|
@ -143,7 +143,10 @@ module.exports = async (ctx, next) => {
|
||||
projectData: project,
|
||||
interfaceData: interfaceData,
|
||||
ctx: ctx,
|
||||
mockJson: res
|
||||
mockJson: res,
|
||||
resHeader: {},
|
||||
httpCode: 200,
|
||||
delay: 0
|
||||
}
|
||||
await yapi.emitHook('mock_after', context);
|
||||
return ctx.body = context.mockJson;
|
||||
|
Loading…
x
Reference in New Issue
Block a user