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. Commented Apr 6, 2021 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
    Commented Apr 6, 2021 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. Commented Apr 6, 2021 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
    Commented Apr 6, 2021 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
    Commented Apr 6, 2021 at 12:44

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .