我正在将 Jhipster 应用程序部署到 Kubernetes 环境,并使用 Istio 进行网络连接。
下面是我的虚拟服务。请注意,当prefix
被设定为/
,一切正常。但是,我有几个应用程序在此集群上运行,因此我需要将其映射到/mywebsite
.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ingress
spec:
hosts:
- "*"
gateways:
- mywebsite-gateway
http:
- match:
- uri:
prefix: /mywebsite
route:
- destination:
host: mywebsite
port:
number: 80
websocketUpgrade: true
当我访问该应用程序时,我收到以下一组错误:
mywebsite:3 GET http://mywebsite.com:31380/app/vendor.bundle.js net::ERR_ABORTED 404 (Not Found)
manifest.bundle.js:55 Uncaught TypeError: Cannot read property 'call' of undefined
at __webpack_require__ (manifest.bundle.js:55)
at eval (app.main.ts?3881:1)
at Object../src/main/webapp/app/app.main.ts (main.bundle.js:447)
at __webpack_require__ (manifest.bundle.js:55)
at webpackJsonpCallback (manifest.bundle.js:26)
at main.bundle.js:1
__webpack_require__ @ manifest.bundle.js:55
eval @ app.main.ts?3881:1
./src/main/webapp/app/app.main.ts @ main.bundle.js:447
__webpack_require__ @ manifest.bundle.js:55
webpackJsonpCallback @ manifest.bundle.js:26
(anonymous) @ main.bundle.js:1
manifest.bundle.js:55 Uncaught TypeError: Cannot read property 'call' of undefined
at __webpack_require__ (manifest.bundle.js:55)
at eval (global.css?ca77:1)
at Object../node_modules/css-loader/index.js!./src/main/webapp/content/css/global.css (global.bundle.js:6)
at __webpack_require__ (manifest.bundle.js:55)
at eval (global.css?0a39:4)
at Object../src/main/webapp/content/css/global.css (global.bundle.js:13)
at __webpack_require__ (manifest.bundle.js:55)
at webpackJsonpCallback (manifest.bundle.js:26)
at global.bundle.js:1
__webpack_require__ @ manifest.bundle.js:55
eval @ global.css?ca77:1
./node_modules/css-loader/index.js!./src/main/webapp/content/css/global.css @ global.bundle.js:6
__webpack_require__ @ manifest.bundle.js:55
eval @ global.css?0a39:4
./src/main/webapp/content/css/global.css @ global.bundle.js:13
__webpack_require__ @ manifest.bundle.js:55
webpackJsonpCallback @ manifest.bundle.js:26
(anonymous) @ global.bundle.js:1
mywebsite:1 Unchecked runtime.lastError: The message port closed before a response was received.
我不知道为什么它要尝试去/app/vendor.bundle.js
。我认为应该去/mywebsite/app/vendor.bundle.js
。虽然当我手动转到此页面时,我得到了Your request cannot be processed
也在我的index.html
, 我有<base href="./" />
,它一直存在,因为我将其视为可能的解决方案。
正如您在评论中提到的
我在 webpack ... 和 index.html 中设置了 new HtmlWebpackPlugin({ baseUrl: '/myapp/' }) 。我收到一些新错误(即找不到 favicon),但该网站仍然无法加载,因为似乎找不到 javascript 或其他东西 – Mike K
这就是它应该如何工作的。它不会加载 javascript,可能还加载 css/img,因为您没有为此显示 istio uri。
所以这里的解决方案是
- 新建baseUrl和basehref,例如/myapp
- 使用 /myapp 前缀或任何前缀创建虚拟服务并重写 /myapp
- 为您的 javascript/css/img 文件夹路径创建额外的 uri
看看这个example
让我们分解一下应该路由到前端的请求:
精确路径/ 应路由到前端以获取 Index.html
前缀路径/static/* 应路由到前端以获取前端所需的任何静态文件,例如层叠样式表 and JavaScript 文件.
与正则表达式 ^.*.(ico|png|jpg)$ 匹配的路径应该路由到前端,因为它是页面需要显示的图像。
http:
- match:
- uri:
exact: /
- uri:
exact: /callback
- uri:
prefix: /static
- uri:
regex: '^.*\.(ico|png|jpg)$'
route:
- destination:
host: frontend
port:
number: 80
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)