0

I get an error when I send a patch request to my api (with loopback 4) , all the other request are working fine , i get error only on patch request .

error :

Access to XMLHttpRequest at 'url api' from origin 'url web app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

any idea please !! this problem it was also on loopback 3 , so i think if migrate to loopback 4 i will solve the problem , but i get always the same error

Yns Dev
  • 11
  • 3
  • Try manually configuring CORS rules as described here: https://loopback.io/doc/en/lb4/Customizing-server-configuration.html#customize-cors – MaxAlex May 30 '22 at 03:10
  • thanks for your help spirit , i already did , here is code in index.ts : const config = { rest: { port: +(process.env.PORT ?? 3000), host: process.env.HOST, gracePeriodForClose: 5000, // 5 seconds openApiSpec: { setServersFromRequest: true, }, cors: { origin: '*', methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', preflightContinue: false, optionsSuccessStatus: 200, maxAge: 86400, credentials: true, }, }, }; – Yns Dev May 30 '22 at 11:08
  • All rest methods work fine except patch method – Yns Dev May 30 '22 at 11:14
  • See the response headers: Access-Control-* in the debugger, how they look for PATCH and for other requests? – MaxAlex May 31 '22 at 02:57
  • Access to XMLHttpRequest at 'http://urlapi/preventives/56' from origin 'https://web.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. – Yns Dev May 31 '22 at 11:58
  • { "headers": { "normalizedNames": {}, "lazyUpdate": null, "headers": {} }, "status": 0, "statusText": "Unknown Error", "url": "https://urlapi.com/preventives/56", "ok": false, "name": "HttpErrorResponse", "message": "Http failure response for https://urlapi.com/preventives/56: 0 Unknown Error", "error": { "isTrusted": true } } – Yns Dev May 31 '22 at 12:01

1 Answers1

1

The same error came to me when i was using cors extension After removing the extension it works for me!

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 28 '22 at 16:24
  • Thank you - worked for me. I just had to turn the extension off and PATCH requests started working – Jamie G Mar 01 '23 at 14:33