# \[Bypassing CORS Errors\] When Accessing the Discuss Endpoint for the Leaderboard

**URL:** <https://discuss.meshery.io/t/bypassing-cors-errors-when-accessing-the-discuss-endpoint-for-the-leaderboard/3886>\
**Category:** Community\
**Tags:** layer5, websites\
**Created:** [October 4, 2023, 12:39pm UTC](https://discuss.meshery.io/t/bypassing-cors-errors-when-accessing-the-discuss-endpoint-for-the-leaderboard/3886 "2023-10-04T12:39:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ajaezo.Kingsley](https://discuss.meshery.io/user_avatar/discuss.meshery.io/ajaezo.kingsley/32/1690_2.png) [@Ajaezo.Kingsley](https://discuss.meshery.io/u/Ajaezo.Kingsley)\
**Post date:** [October 4, 2023, 12:39pm UTC](https://discuss.meshery.io/t/bypassing-cors-errors-when-accessing-the-discuss-endpoint-for-the-leaderboard/3886/1 "2023-10-04T12:39:36Z")

</div>

**Introduction:**

While working on our React.js leaderboard project, I encountered CORS (Cross-Origin Resource Sharing) errors when trying to access the Discuss endpoint. In this post, I’ll share a quick and efficient solution that involves adding a proxy to the `package.json` file.

**Section 1: The Problem**  
When attempting to access the Discuss endpoint within our React.js project, CORS errors posed a significant hurdle. These errors prevented the frontend from making requests to the Discuss API due to security restrictions in this [[https://discuss.meshery.io/directory\_items.json?period=all](https://discuss.meshery.io/directory_items.json?period=all)]([https://Discuss](https://Discuss) Endpoint) API endpoint. to fetch the leaderboard data and render it in a datagrid or table

**Section 2: The Solution**

To bypass CORS errors in our React.js project, I added a proxy configuration to the `package.json` file. This proxy acts as an intermediary between the frontend and the Discuss API, allowing seamless communication.

**Section 3: Implementation**

Here are the steps to implement the proxy in your React.js project:

1. Open the `package.json` file in your project’s root directory.

2. Add a `"proxy"` key with the target URL of the Discuss API as its value. For example:

```auto
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "proxy": "https://discuss.meshery.io/"
}

```

 ![Screenshot 2023-10-04 at 1.31.31 PM](https://discuss.meshery.io/uploads/default/original/2X/b/b0622742f7e1cff731cf9d0fb0833562c0d06f93.jpeg)

With our major focus the ‘proxy’ key

1. Save the `package.json` file.

That’s it! React will now automatically proxy requests to the specified URL, effectively bypassing CORS restrictions.

I conducted thorough testing to verify that the proxy configuration successfully bypassed CORS errors. During testing, all Discuss endpoint requests from the frontend worked without any CORS-related issues.

**Conclusion**

In conclusion, the solution of adding a proxy to the `package.json` file in our React.js project effectively resolved CORS errors when accessing the Discuss endpoint. This approach simplifies development and ensures a smooth user experience while maintaining security.

**Discussion**  
I invite you to share your experiences with handling CORS issues not just specific to the leaderboard but also in React.js projects in general and any additional tips or insights you may have. Let’s engage in discussion!
