Jaagrav / CodeX

CodeX is an online compiler for various languages like Java, C++, Python, etc. Execute code in various languages on your own website for free with the CodeX API!!!
https://codex.jaagrav.in/
268 stars 65 forks source link

CORS Error, While Using in ReactJS Application #3

Closed asmitsirohi closed 2 years ago

asmitsirohi commented 3 years ago

I'm trying to use this api in my ReactJS application, and facing CORS error.

Code: var data = JSON.stringify({ code: public class program{ public static void main(String [] args){ System.out.println("Hello"); } }, language: "java", input: "", });

  const response = await axios.post(
    "https://codexweb.netlify.app/.netlify/functions/enforceCode",
    {
      data: data,
    },
    {
      headers: {
        "access-control-allow-origin": "*",
        "Content-type": "application/json; charset=UTF-8",
      },
    }
  );

Error ScreenShot: image

Jaagrav commented 2 years ago

This api works only in backend, for example with nodejs, in order to use it in front end you need to add this URL as a prefix https://cors-anywhere-jaagrav.herokuapp.com/https://codexweb.netlify.app/.netlify/functions/enforceCode and it should work

asmitsirohi commented 2 years ago

Thanks....It helps a lot.

Alex-Beep-Cao commented 2 years ago

Really Helpful, thank you very much!!!

Jaagrav commented 2 years ago

The API now supports No CORS requests so you don't need to follow the above comment any more. Check out the new docs, https://github.com/Jaagrav/CodeX-API