Search code examples
reactjsspring-bootoffice-jsoffice-addinsoutlook-web-addins

React fetch not working with localhost endpoint with spring boot backend but ok with dummy JSON data


I'm working on an Office Add-in for Outlook, build in React with Yeoman Generator (https://github.com/OfficeDev/Office-Addin-TaskPane-React.git)

The principle is pretty simple, when I click a button in the Outlook ribbon, it has to replace the mail Signature with a new one fetched through an API.

Here's the thing : when I write some hard coded html: no problem. And when I replace an Outlook Signature with a dummy data from jsonplaceholder, everything works fine as well: my signature is correctly replaced.

But as soon as I try to fetch it from my backend built on Spring Boot and running on Localhost, nothing works as expected. My endpoint is working fine and sends correct JSON response in Postman or in my browser.

Action launched on click :

getRemoteSignature().then(
(signature) => {
  // replace 'htmlSignature' by 'title' for dummy data test
  item.body.setSignatureAsync(signature.htmlSignature, {
    coercionType: "html",
  })
});

My function to fetch data from my API:

async function getRemoteSignature() {
  // So this one works fine and replaces my signature in outlook
  const response = await fetch('https://jsonplaceholder.typicode.com/posts/1');
  // This one is a pain in the a** and doesn't want to work
  const response = await fetch('https://localhost:8443/api/v1/signature/find/1');
  const signature = await response.json();
  return signature;
}

My Outlook Add-in is running in https://localhost:3000 with node.js, my SpringBoot backend runs on https://localhost:8443 with tomcat.

Thanks for your help if someone has an idea of what is going on or what I did wrong...


Solution

  • Edit

    Ok, as I suspected it was a matter of self-signed certificate. I disabled the SSL in my back-end and pointed back my fetch to http://localhost:8000/api/v1/signature/find/1 and everything worked : my signature was replaced in my email in Outlook.

    The only thing I have left to do is finding a way to install a better certificate in my backend i guess.