prasmussen / glot-run

API for running code inside docker containers

Home Page:https://run.glot.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CORS issue

itaditya opened this issue · comments

Hi I'm unable to make an AJAX request to glot.io. I keep getting this error.

Failed to load https://run.glot.io/languages/python/latest: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 405.

Hi I am not able to call https://run.glot.io/languages/python/latest in Angular 5 application it gives following error.

Failed to load https://run.glot.io/languages/python/latest: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 405.
screenshot 226

Yeah, CORS is not supported at this time. I'm currently working on a new version of the api where I will consider allowing it. It will take at least a couple of months before the new api is ready though.

So we can't run code in glot from localhost? Is there a workaround for that?

Create a backend server. From your frontend send a request to the server and from the server make a request to glot. For a working implementation check out https://github.com/itaditya/Code-Runner

Aaah I see, thanks. Sorry, why does this work? I thought if a request didn't work from the front, it wouldn't work from the back either.

A request sent from browser i.e. Ajax is different from what is sent by the server. Since the request on the client side can be tampered by bad actors, it is less secure that is why cors exist to prevent sending requests from client side. Many Payment gateways also accept request from server only

is this fixed @prasmussen

@prasmussen, I see some unused code for CORS
https://github.com/prasmussen/glot-run/blob/master/apps/glot/src/http/http_util.erl#L72-L83

Would you accept a PR?

Sorry, but I won't do any changes to the current version in regards to CORS