3

I am deploying a Jhipster app to a Kubernetes environment, and am using Istio for the networking.

Below is my VirtualService. Note that when the prefix is set to /, everything works fine. However I have several apps running on this cluster, so I need to map it to /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

When I access the app, I get these set of errors:

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.

I'm not sure why it is trying to go /app/vendor.bundle.js. I think it should go to /mywebsite/app/vendor.bundle.js. Although when I go to this page manually, I get a Your request cannot be processed

Also in my index.html, I have <base href="./" />, which had always been there ,as I read that as a possible solution.

Mike K.
  • 543
  • 3
  • 14
  • 46
  • Did you set baseHref as explained in https://www.jhipster.tech/production/#running-the-application-under-a-context-path – Gaël Marziou May 19 '20 at 23:26
  • What if you add [rewrite](https://istio.io/docs/reference/config/networking/virtual-service/#HTTPRewrite) to `/`? Try this in your virtual service and let me know if that works, `http: - match: - uri: prefix: /mywebsite rewrite: uri: /`. – Jakub May 20 '20 at 08:44
  • @GaëlMarziou I set `new HtmlWebpackPlugin({ baseUrl: '/myapp/' })` in the webpack ... and `` in the index.html. I get some new errors (ie. can't find favicon), but still the site doesn't load as doesn't seem to find the javascript or soemthing – Mike K. May 20 '20 at 16:43
  • @jt97 I added rewrite: uri: "/"and rewrite: uri: "/myapp" and it is doing the same thing (still broke) – Mike K. May 20 '20 at 16:43

1 Answers1

1

As you mentioned in comments

I set new HtmlWebpackPlugin({ baseUrl: '/myapp/' }) in the webpack ... and in the index.html. I get some new errors (ie. can't find favicon), but still the site doesn't load as doesn't seem to find the javascript or soemthing – Mike K

That's how it supposed to work. It doesn't load javascript and probably css/img's because you didn't show istio uri for this.

So the solution here is

  • Make new baseUrl and basehref, for example /myapp
  • Create virtual service with /myapp prefix or any prefix and /myapp rewrite
  • Create additional uri's for your javascript/css/img's folder path

Take a look at this example

Let’s break down the requests that should be routed to Frontend:

Exact path / should be routed to Frontend to get the Index.html

Prefix path /static/* should be routed to Frontend to get any static files needed by the frontend, like Cascading Style Sheets and JavaScript files.

Paths matching the regex ^.*.(ico|png|jpg)$ should be routed to Frontend as it is an image, that the page needs to show.

http:
  - match:
    - uri:
        exact: /
    - uri:
        exact: /callback
    - uri:
        prefix: /static
    - uri:
        regex: '^.*\.(ico|png|jpg)$'
    route:
    - destination:
        host: frontend             
        port:
          number: 80
Jakub
  • 8,189
  • 1
  • 17
  • 31