How to integrate CORS with my Video Hosting application I'm putting together?

38 views
Skip to first unread message

Jordan Simpson

unread,
Sep 6, 2015, 12:15:37 AM9/6/15
to nodejs

A couple friends and I are working on a video hosting / sharing platform and none of us have worked with CORS before. From what I've read, it allows third parties to display or alter your data?


Our goal is to integrate our video hosting website with the RES (Reddit Enhancement Suite) browser plugin This will allow our videos automatically embedded inside Reddit, similar to how YouTube and Imgur is.


The RES team asks for a client-side js file, which they offer examples here: https://github.com/honestbleeps/Reddit-Enhancement-Suite/blob/master/lib/modules/hosts/example.js


Then, you need to make sure CORS is correctly setup for XHR. After inspecting my page that displays the videos, I assume this is what needs to be available for them:

http://i.imgur.com/DLo6r6T.jpg


Because RES is open source, I can compile a version of RES using my client-side script and be able to test on my own. I can't figure out how to use CORS correctly. I've read a lot about it, but would really appreciate at a nudge in the right direction.


I have two routes that have to do with my videos. Here they are below:


    //video routes

    app.route('/media').get(articles.getVideos);

    app.route('/media/:id').get(articles.play);


If there's anything else needed for me to provide, let me know. Thanks!

asleepysamurai

unread,
Sep 7, 2015, 2:22:13 AM9/7/15
to nodejs
CORS or cross origin resource sharing is a mechanism by which you can allow specific third party origins to access resources on your site. To do this you need to setup an access-control-allow-origin header in the response to the request from the RES plugin. You should go through https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS to get a good idea of CORS.

Once you figure out the CORS strategy you want to use, simply add that header to the response using res.set (if you are using express).
Reply all
Reply to author
Forward
0 new messages