Search code examples
javascriptreactjscorsmedia-playervideo.js

Are there any CORS workaround without server side change in Javascript?


I am trying to access a publicily shared google drive video file from my react website , since google drive file is not a absolute downloadable file,I am trying to play google drive video with a Custom Player ,so before showing the video in the player , I need to extract absolute file url with an XHR request.But I cannot access googledrive.com with XHR beacause it will only get CORS errors.Is there a way to request other server domains from a client domain without any serverside changes?


Solution

  • Short Answer

    No. It's impossible to get around CORS without modifying server-side code.

    Long Answer

    CORS (Cross Origin Resource Sharing) is a browser's way of letting developers connect to external APIs from your website.

    But that is an obvious security risk, not all APIs are meant to be public. To fix this risk, CORS only allows you to communicate to servers that have CORS enabled.

    Unless the owners of the server suddenly decide to enable CORS, you cannot make a request from your website to the server.

    The only way

    The only way to achieve your goal is to send the request from a server. When making requests from server to server, there is no CORS (it only exists on browsers).

    You would have to create a server yourself, make the request there, and send the response to the client.