-
Notifications
You must be signed in to change notification settings - Fork 26
feat: intercepts the mock returned by the me interface. #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * Mock 路由配置 | ||
| * 用于纯前端项目的接口 mock | ||
| */ | ||
|
|
||
| // Mock 用户数据(真实接口返回格式) | ||
| const mockUserData = { | ||
| data: { | ||
| id: 1, | ||
| username: '开发者', | ||
| email: 'developer@lowcode.com', | ||
| provider: null, | ||
| password: null, | ||
| confirmationToken: 'uuid~dfafasdfasdfa', | ||
| confirmed: true, | ||
| blocked: false, | ||
| created_by: null, | ||
| updated_by: null, | ||
| created_at: '2021-11-11T13:52:21.000Z', | ||
| updated_at: '2022-11-01T01:39:30.000Z', | ||
| block: false, | ||
| is_admin: true, | ||
| is_public: false, | ||
| }, | ||
| locale: 'zh-cn', | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| // 格式化响应数据 | ||
| const getResponseData = (data) => { | ||
| return { | ||
| data, | ||
| error: null, | ||
| }; | ||
| }; | ||
|
|
||
| export default [ | ||
| // 获取用户信息 | ||
| { | ||
| url: /\/api\/user\/me$|\/user\/me$/, // 使用正则表达式匹配 | ||
| method: 'GET', | ||
| response: async () => { | ||
| return [200, getResponseData(mockUserData)]; | ||
| }, | ||
| }, | ||
| ]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Search for enableMock configuration and environment checks
rg -n 'enableMock' --type=js --type=json -g '!node_modules'Repository: opentiny/tiny-pro Length of output: 140 🏁 Script executed: # Search for environment-based conditionals related to mocking
rg -n -B3 -A3 'NODE_ENV|VITE_|VUE_APP_' template/lowcode-designer/src/composable/http/ --type=jsRepository: opentiny/tiny-pro Length of output: 642 🏁 Script executed: # Find where mockConfig.js is imported
rg -n 'mockConfig|from.*mockConfig' template/lowcode-designer/src/composable/http/ --type=jsRepository: opentiny/tiny-pro Length of output: 339 🏁 Script executed: # Look at the index.js file in the same directory
cat -n template/lowcode-designer/src/composable/http/index.js | head -50Repository: opentiny/tiny-pro Length of output: 1743 🏁 Script executed: # Get context around line 195 where enableMock is set
cat -n template/lowcode-designer/src/composable/http/index.js | sed -n '180,210p'Repository: opentiny/tiny-pro Length of output: 676 🏁 Script executed: # Also check if there's any conditional logic around where the config is used/applied
cat -n template/lowcode-designer/src/composable/http/index.js | sed -n '40,70p'Repository: opentiny/tiny-pro Length of output: 1508 🏁 Script executed: # Search for how enableMock is used in the codebase
rg -n 'enableMock' --type=js -B5 -A5Repository: opentiny/tiny-pro Length of output: 915 🏁 Script executed: # Check if there's a build-time check or other safeguard for mocking in production
rg -n -i 'production|prod.*mock|mock.*prod' template/lowcode-designer/src/composable/http/ --type=jsRepository: opentiny/tiny-pro Length of output: 43 🏁 Script executed: # Check the getConfig function more completely to see full environment logic
cat -n template/lowcode-designer/src/composable/http/index.js | sed -n '170,186p'Repository: opentiny/tiny-pro Length of output: 587 Gate The enableMock: getConfig().enableMock ?? import.meta.env.MODE?.includes('dev')Or pass the environment check explicitly: const isDev = import.meta.env.MODE?.includes('dev')
// ...
enableMock: isDevThis ensures mocks never run in production builds. 🤖 Prompt for AI Agents |
||
Uh oh!
There was an error while loading. Please reload this page.