Skip to content

master 分支mock-server 热更新兼容问题及建议 #1860

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

Closed
AleynHe opened this issue Apr 8, 2019 · 10 comments
Closed

master 分支mock-server 热更新兼容问题及建议 #1860

AleynHe opened this issue Apr 8, 2019 · 10 comments

Comments

@AleynHe
Copy link

AleynHe commented Apr 8, 2019

Bug report(问题描述)

问题(/mock/mock-server.js )

  1. 方法getMockRoutesIndex循环溢出,去除=
  2. 热更新后,mockRoutesLength 长度不更新,导致增加、减少mock路由后异常express异常,应在每次调用registerRoutes后,刷新长度值
  3. 不兼容(windows),unregisterRoutes、getPath;路径字符串'/'问题导致。
  4. getPath是否一定有必要存在??

优化建议

现有mock api路由前缀固定,并在mock-server热更新代码中写死,不太适用于前后端项目,联调阶段(一键切换联调接口,特别是后端微服务化之后)
解决:

  1. 去掉/mock/index.js responseFake中写死mock 路由前缀/mock
  2. 记录registerRoutes(/mock/mock-server.js)第一次注册进express的路由正则 URL,并转换为源字符串mockFirstRouteUrl返回(同mockRoutesLength)
  3. getMockRoutesIndex(/mock/mock-server.js)将IF判断includes('mock')更改为b)步骤中记录的includes(mockFirstRouteUrl)
  4. vue.config.js 代理/mock前缀,本地mock api是否有必要配置代理?

Steps to reproduce(问题复现步骤)

见问题描述

Screenshot or Gif(截图或动态图)

Link to minimal reproduction(最小可在线还原demo)

Other relevant information(格外信息)

  • Your OS: windows 10
  • Node.js version: v8.12.0
  • vue-element-admin version: master-2019-04-08
@PanJiaChen
Copy link
Owner

欢迎pr

@AleynHe
Copy link
Author

AleynHe commented Apr 8, 2019

有点忙,争取本周抽空给PR

@PanJiaChen
Copy link
Owner

PanJiaChen commented Apr 9, 2019

dbee6ff

@Aysnine 我优化了下,用更简单的方式来清除 _router.stack

illidanet pushed a commit to illidanet/vue-element-admin that referenced this issue Apr 12, 2019
@dingangang
Copy link
Contributor

win10下还是热更新失效。
修改mock返回数据,页面返回数据不会改变,需要重启工程才能生效,

@PanJiaChen
Copy link
Owner

@dingangang 我晚点找台windows测一下。

@dingangang
Copy link
Contributor

大佬,我在ubuntu上跑了一下是正常的。win10还是不正常。
mock-server.js:
console.log(chalk.magentaBright(\n > Mock Server hot reload success! changed ${path}))
win10上控制台上面这条语句是执行了的。就是页面刷新后接口返回的数据还是原来的。
/mock 文件夹下的任何修改当前都不会有反应。

@PanJiaChen
Copy link
Owner

感谢你的反馈。

@hswyxj
Copy link

hswyxj commented Apr 18, 2019

mock-server.js:
unregisterRoutes 路径字符串'/'问题导致。
把 i.includes('/mock') 改成i.includes('./mock')即可

我的Windows7正常了

@dingangang
Copy link
Contributor

mock-server.js:
unregisterRoutes 路径字符串'/'问题导致。
把 i.includes('/mock') 改成i.includes('./mock')即可

我的Windows7正常了

win10下我修改后还是不正常。

@dingangang
Copy link
Contributor

dingangang commented Apr 18, 2019

if (i.includes('/mock') || i.includes('\\mock') || i.includes('./mock'))
修改了一下函数,我提了一个pr。这样应该都正常了。

@AleynHe AleynHe closed this as completed Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants