简体   繁体   English

s4sdk-无法连接到NodeJS微服务

[英]s4sdk - Cannot connect to NodeJS microservice

I was in the proccess of extending the tutorial mentioned in Step 9, with a NodeJS micro service. 我正在使用NodeJS微服务扩展第9步中提到的教程。 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. 我的流程是一个应用路由器,该路由器定向到HTML5微服务(静态buildpack),并且消耗Java或NodeJS微服务。 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). Java部分与身份验证范围一起正常工作,但是对于NodeJS,当我调用各自的路径/ node / hello时,我总是会收到404(未找到)错误(hello应该返回服务器的函数输出)。

This is the xs-app.json I am using for routing 这是我用于路由的xs-app.json

{
  "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. 问题在/ node块上,其他都可以正常工作。 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. 我还注意到了另一个奇怪的问题,即如果我将默认目标(/)从business-partner-frontend替换为business-partner-node,则应用路由器会成功地通过传播身份验证的方式调用节点js服务器,因此出现了问题与xs-app文件相关,而与目标本身无关。

I have also unsuccessfully tried to add the port to the destination and adding a staticfile mapping the html5 project but without success. 我也尝试将端口添加到目标并添加映射html5项目的静态文件,但未成功。

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. 当前路径与source的第一个匹配将确定路径。 In your case, the / of the second route matches all paths, including /node/... . 就您而言,第二条路由的/匹配所有路径,包括/node/...

Reorder your routes so that the node destination comes before the frontend destination. 重新排序您的路由,使节点目标位于前端目标之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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