【问题标题】:Loopback rest connector remote with multiple method not working具有多种方法的环回休息连接器遥控器不起作用
【发布时间】:2021-05-21 11:21:19
【问题描述】:

我使用 Loopback4 作为 Central API。我正在尝试通过 Loopback 中的远程方法调用 3rd 方 API 的方法。我使用 Strapi 作为第 3 方 API 并将其传达给 loopback4

使用 Loopback,我有一个如下所示的数据源:

const strapiConfig = {
  name: 'strapi',
  connector: 'rest',
  baseURL: appConfig.strapi.host,
  crud: false,
  options: {
    headers: {
      "accept": "application/json",
      "content-type": "application/json",
      "cache-control": "no-cache",
      "Authorization" : `Bearer ${appConfig.strapi.token}`
    }
  },
  operations: [
    {
      "template": {
        "method": "GET",
        "url": `${strapiUrl}/pages/{pageId}`
      },
      "functions": {
        "getOnePage": ["pageId"]
      }
    },
    {
      "template": {
        "method": "GET",
        "url": `${strapiUrl}/pages`
      },
      "functions": {
        "getPages": ""
      }
    },
    {
      "template": {
        "method": "GET",
        "url": `${strapiUrl}/glossary/{id}`
      },
      "functions": {
        "getOneGlossary": ['id']
      }
    },
    {
      "template": {
        "method": "GET",
        "url": `${strapiUrl}/glossary`
      },
      "functions": {
        "getGlossary": ""
      }
    },
    {
      "template": {
        "method": "GET",
        "url": `${strapiUrl}/faq`
      },
      "functions": {
        "getFaqs": ""
      }
    },
    {
      "template": {
        "method": "GET",
        "url": `${strapiUrl}/faq/{id}`
      },
      "functions": {
        "getOneFaq": ['id']
      }
    }
  ]
};

唯一有效的端点是页面

欢迎任何建议。谢谢!

【问题讨论】:

    标签: node.js strapi loopback4


    【解决方案1】:

    在调用其他 Endpoints 时,您会得到什么样的错误/状态代码?

    您是否在 Strapi 中设置了角色和权限? 示例(取决于 Strapi 版本):

    1. 导航到设置 - 用户和权限插件。

    2. 点击公共角色。

    3. 在权限下向下滚动,打开应用程序选项卡并找到您要编辑的集合类型。

    4. 即单击旁边的复选框以查找和查找。

    5. 点击保存

    检查:https://strapi.io/documentation/developer-docs/latest/getting-started/quick-start.html#_7-set-roles-and-permissions

    【讨论】:

    • 我解决了.. 这是我自己的错误。我的配置 url 应该与来自 strapi 端点的端点匹配。在我上面的配置中,我尝试将其与我当前的环回端点匹配。所以它现在固定了。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    • 2019-10-18
    相关资源
    最近更新 更多