如何在 LoopBack 4 中的所有网络接口上启动 HTTP Server

How to start HTTP Server on all network interfaces in LoopBack 4

我使用 LoopBack 4 cli 创建了一个新应用程序。我想在所有接口 0.0.0.0 而不是 127.0.0.1 上启动应用程序。

我该怎么做?

还有如何更改应用程序启动的端口号?

对于 LB4:

如果您使用的是 RestApplication,根据 this and this

你可以在这里传递主机:

const app = new RestApplication({
  rest: {
    port: 3001,
    host: "my-host"
  },
});

或者,如果您使用自己的应用程序来扩展任何应用程序,您可以将其传递给 super:

export class MyApplication extends RestApplication {
  constructor() {
    super({
      rest: {
        port: 4000,
        host: 'my-host',
      },
    });
  }
}

如果您使用的是 LB3:
/server 文件夹中有一个名为 config.json 的配置文件。 将 host 更改为:

{
  "restApiRoot": "/v1",
  "host": "0.0.0.0",
  "port": 5000,
  .
  .
  .
  "legacyExplorer": false
}