简体   繁体   中英

s4sdk - Cannot connect to NodeJS microservice

I was in the proccess of extending the tutorial mentioned in Step 9, with a NodeJS micro service. However I am having some strange issue with the comunication to the backend.

The flow I have is an App Router that directs to an HTML5 micro service (static buildpack) and this consumes either a Java or NodeJS microservice. The Java part works fine along with authentication scopes, but for NodeJS I am always getting 404 (not found) error when I call the respective path /node/hello (hello should return a function output from server).

This is the xs-app.json I am using for routing

{
  "welcomeFile": "index.html",
  "authenticationMethod": "route",
  "websockets": {
    "enabled": true
  },
  "routes": [
    {
      "source": "/odata/v4/(.*)",
      "target": "/odata/v4/$1",
      "destination": "business-partner-api"
    },
    {
      "source": "/",
      "target": "/",
      "destination": "business-partner-frontend"
    },
    {
      "source": "/node/(.*)",
      "target": "/$1",
      "destination": "business-partner-node"
    }
  ]
}

The issue is on the /node block the others work fine. I have also noticed another strange issue, is that if I replace the default destination (/) from business-partner-frontend to business-partner-node the app router sucessfully calls the node js server with the authentication being propagated so it appears the issue is somehow related with the xs-app file and not in the destination itself.

I have also unsuccessfully tried to add the port to the destination and adding a staticfile mapping the html5 project but without success.

Anything I might be missing on the node part config?

Best Regards,

The issue is probably in the order of your routes, which is important for the routing. The first match of the current path against source will determine the route. In your case, the / of the second route matches all paths, including /node/... .

Reorder your routes so that the node destination comes before the frontend destination.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM