通过插件到服务器中间件的api-call
我已经配置了一个插件和自定义服务器中间件扩展名。
我能够通过服务器中间件来通过我的插件来调用函数,如下图:
插件:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您为您的特殊情况创建一个“自定义融合”,您可以在其中添加新层而没有任何问题。您可以检查例如故事书一个:)
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