Frappe Framework ERPNEXT: How to enable CORS on localhost

3.7k views Asked by At

I am trying to develop a React Client that consumes the Frappe REST API but on each request I am getting a CORS error. according to the community forum, I have to edit the Nginx conf to allow CORS requests but I am facing this error on my machine (localhost) and the dev server is not Nginx so how can I allow CORS requests on localhost?

3

There are 3 answers

0
Omkar Darves On
// site_config.json
{
  // allow all origins
  "allow_cors": "*"

  // restrict to Origin:
  "allow_cors": ["http://demo-site.com"]
}

Reference: https://github.dev/frappe/frappe/blob/07af98255b6ac9bb3b277fc1b9d6999a86a90e9f/frappe/app.py#L159

0
salih On

Add "allow_cors": "*" to common_site_config.json and restart bench

0
Faris Ansari On

I don't think you need to configure CORS, especially during local development. Let's say your React client is running the port 8080 and Frappe server is on 8000. You can proxy all your requests from localhost:8080 to localhost:8000.

In production, you can generate the static assets and put them in the www folder of the Frappe app.