0

I created an LWC OSS app with express server using npx create-lwc-app:

  • Do you want to use the simple setup? Yes
  • Package name for npm demo-app
  • Select the type of app you want to create Standard web app
  • Do you want a basic Express API server? Yes

enter image description here

I paste the component miscRestApiCall from reciepe in the client and the other elements needed (my own code repo here : https://github.com/jeremyvial/testcallapilwcoss) but when I try the API call, I got error in the fetch function ( https://testlwcframworkk.herokuapp.com/ ) linked to the CSP.

Any clue about how and where i can autorise the call in the context of express server ?

enter image description here

6
  • 2
    You need to set the CSP policy in your node JS application response header. Check this article. – Rahul Gawale Apr 6 at 11:51
  • @rahulgawale I may update the wrong file but already did it reusing helmet module provided github.com/jeremyvial/testcallapilwcoss/blob/main/scripts/… – Badbaxx Apr 6 at 11:55
  • This is the correct file but as per the error message your policy has been ignored. I have never used Helmet so no Idea why is it being ignored. – Rahul Gawale Apr 6 at 12:03
  • Me neither, just reused the exemple script :) I will try without the helmet module. But as there is 2 server running (front hosting lwc and express hosting an api server) I'm affraid I have some confusion between the 2 NodeJs server. – Badbaxx Apr 6 at 12:17
  • Are you performing the api call from the Server? or the Client? fyi: I copy pasted the code from the recipe, and everything ran without issue. I am performng the api call from the client (lwc js file). – glls Apr 6 at 12:44
0

Finally found the problem. When I compare with the recepe script, I see that I uses helmet function in the wrong order enter image description here

EDIT : If you want call the webservice host by the back express server there is this great tutorial : https://www.youtube.com/watch?v=WHD5VZVabNw

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.