Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景 / Motivation
Resolve #830
目前每个接口都需要单独维护相同的返回头逻辑以及相同的 mock 方法:
本 PR 引入了公共工具模块,统一管理响应头和 Mock 方法,实现“一处定义,多处使用”。
变更内容 / What’s changed
新增公共工具模块 (server/utils/commonMock.js)
commonResponseHeaders和设置方法,统一管理 CORS 等通用响应头。mockUtils工具类,提供常用的 mock 方法:Mock 服务改造 (server/middleware/mockServer.js)
OPTIONS) 请求和正常 Mock 请求的 header 处理逻辑。Mock 脚本沙箱增强 (server/utils/commons.js)
utils(指向mockUtils)。设计说明 / Design notes
非侵入式扩展:
utils对象注入到脚本沙箱中,不改变原有脚本的Mock或Random对象行为。utils,其行为保持完全一致(向后兼容)。易于维护:
测试说明 / How to test
1. 安装依赖 & 启动项目 / Setup