spring-bootcloud-foundrypivotal-web-services

Cloud Foundry css file returns 502 Bad Gateway: Registered endpoint failed to handle the request


I pushed my spring boot app with VUE frontend to Cloud Foundry. When I send request to static file (css/img/js) such as https://bd-contacts-gateway.cfapps.io/js/chunk-vendors.8b8c1d1d.js

I get

502 Bad Gateway: Registered endpoint failed to handle the request.

In my spring boot app I have static files in src/main/resources/js, src/main/resources/css, src/main/resources/img

This is my manifest.yml when pushing to CF

---

applications:

- name: bd-contacts-gateway

  memory: 1024M

  buildpack: staticfile_buildpack

  routes:

  - route: bd-contacts-gateway.cfapps.io

EDIT:

This is extract from cf logs when calling swagger-ui URL:

2019-09-11T11:34:04.60+0200 [RTR/10] OUT bd-contacts-gateway.cfapps.io
- [2019-09-11T09:34:04.491+0000] "GET /swagger-ui.html HTTP/1.1" 502 0 67 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Safari/605.1.15" "10.10.66.115:63512" "10.10.148.61:61150" x_forwarded_for:"80.242.35.228, 10.10.66.115" x_forwarded_proto:"https" vcap_request_id:"6ccc526a-00c6-4a80-46c1-4c4eee6fcab7" response_time:0.115106066 app_id:"b5dc7fb4-a52a-4997-93cb-9ed40a158bcc" app_index:"0" x_b3_traceid:"3b50452335bafcf9" x_b3_spanid:"3b50452335bafcf9" x_b3_parentspanid:"-" b3:"3b50452335bafcf9-3b50452335bafcf9"

Solution

  • I found the solution. I had to add remote_ip_header and protocol_header in my application-cloud.yml properties. Like this:

    server:
      port: 8080
      tomcat:
        remote_ip_header: x-forwarded-for
        protocol_header: x-forwarded-proto
    
    eureka:
      client:
        serviceUrl:
          defaultZone: http://bd-contacts-eureka.cfapps.io/eureka/
      instance:
        hostname: ${vcap.application.uris[0]}
        nonSecurePort: 80