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)
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