通过插件到服务器中间件的api-call

发布于 2025-02-04 21:06:11 字数 1261 浏览 4 评论 0原文

我已经配置了一个插件和自定义服务器中间件扩展名。

我能够通过服务器中间件来通过我的插件来调用函数,如下图:

插件:

async function getPriceInitiator() {

        const response = await axios({
          method: "post",
          url: "http://localhost:3000/api/myCustomServerMiddleware/testFunction",
        });
        return response
      }
    }

服务器中间件:

function testFunction() {
    return "predefindedResponseString";
  });

我似乎无法在服务器中间件中调用API就像:

async function testFunction() {
  try {
    const res = await axios({
      method: "get",
      url: 'https://www.boredapi.com/api/activity',
    });
    return res;
  } catch (e) {
    console.warn(e);
  }
}

尝试调用API会给我带来错误:“证书已过期”,并且将 wayers 返回我一个空数据对象。看起来很奇怪,因为我可以在响应中传递字符串,然后它确实可以正常工作,如第一个Server Middleware sippet中所示。

编辑: 证书错误如下:

certificate has expired                                                                       13:40:29

      at TLSSocket.onConnectSecure (node:_tls_wrap:1530:34)
      at TLSSocket.emit (node:events:520:28)
      at TLSSocket._finishInit (node:_tls_wrap:944:8)
      at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:725:12)

I have configured a plugin and a custom Server Middleware extension.

I am able to call functions via my plugin from the server middleware as seen in the snippet below:

Plugin:

async function getPriceInitiator() {

        const response = await axios({
          method: "post",
          url: "http://localhost:3000/api/myCustomServerMiddleware/testFunction",
        });
        return response
      }
    }

Server Middleware:

function testFunction() {
    return "predefindedResponseString";
  });

I can not seem to call API's in the server middleware like:

async function testFunction() {
  try {
    const res = await axios({
      method: "get",
      url: 'https://www.boredapi.com/api/activity',
    });
    return res;
  } catch (e) {
    console.warn(e);
  }
}

Trying to call API's will give me errors like: "certificate has expired" and will always return me an empty data object. What seems weird because I can pass strings in the response, then it does work as shown in the first server middleware snippet.

EDIT:
The Certificate error is as follows:

certificate has expired                                                                       13:40:29

      at TLSSocket.onConnectSecure (node:_tls_wrap:1530:34)
      at TLSSocket.emit (node:events:520:28)
      at TLSSocket._finishInit (node:_tls_wrap:944:8)
      at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:725:12)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆一缕阳光ご 2025-02-11 21:06:11

我建议您为您的特殊情况创建一个“自定义融合”,您可以在其中添加新层而没有任何问题。您可以检查例如故事书一个:)

https://github.com/vuestore.com/vuestorefront/storyblont/storyblok

What I would recommend is for you to create a "custom-integration" for you special cases, where you can add new layers without any problem. You can check for example the storybook one :)

https://github.com/vuestorefront/storyblok

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文