vite 打包上线后页面静止一段时间(半小时+)路由跳转无响应

问题

项目在本地开发没问题,但是打包到测试环境时发现页面无操作静止半小时+后,点击事件、接口等都无异常,页面跳转失效,(window.open正常,router.push、router.go(-1)等失效),查看控制台报错

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/html”. Strict MIME type checking is enforced for module scripts per HTML spec.

触发路由跳转时,报错

TypeError: Failed to fetch dynamically imported module

项目配置

组件 版本
vue ^3.2.37
vue-router ^4.0.13
vite ^3.0.9

解决办法

起初怀疑是期间有人更新前端包,但是经过测试并不是,看网上的说法配置了import.meta.glob依旧没解决,经过老大的指点在nginx.conf的 location / 下添加这行代码解决了问题

proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;

之前只是在确定的接口下配置了这行代码,但是测试说,一般在location下是不用加的,Nginx通过反向代理做负载均衡时,如果被代理的其中一个服务发生错误或者超时的时候,通常希望Nginx自动重试其他的服务,从而实现服务的高可用性。实际上Nginx本身默认会有错误重试机制,并且可以通过proxy_next_upstream来自定义配置。
至此,记录下困扰了我n天的bug,立碑警醒。

猜你喜欢

转载自blog.csdn.net/qq_45840993/article/details/128640864
今日推荐