The problem
I tested the LLM from Infomaniak the other day and I struggled with the CORS (Cross-Origin Resource Sharing) issue again.
It is a recurring issue when you host your app on the https://my-app.com
and it requests an api on https://api.example.com
.
The browser will prevent you from doing so unless the backend allows the frontend explicitly with the Access-Control-Allow-Origin
header, hopefully not *
.
MDN describes in detail the concept on their website.
The Solution
If you use Netlify, you can use two methods:
netlify.toml
file
As this Netlify thread states, you need to define a rewrite rule:
|
|
A _redirects
File
This option is the same as above, but you write it differently:
|
|
Also, be sure to name the file _redirects
and place it in the public
directory.
Credits: Photo by Markus Spiske on Unsplash.