illuspas / Node-Media-Server

A Node.js implementation of RTMP/HTTP-FLV/WS-FLV/HLS/DASH/MP4 Media Server
https://www.npmjs.com/package/node-media-server
MIT License
5.96k stars 1.52k forks source link

Accessing API and getting CORS Problem? #116

Open alekseykravetz opened 6 years ago

alekseykravetz commented 6 years ago

Hi,

I'm trying access Node-Media-Server API (http://{my-server}:8000/api/server) and I get CORS problem.

I could fix the issue if i'm adding the following line: res.header('Access-Control-Allow-Origin', '*'); at api\controllers\server.js at line 111, but I'm pretty sure that it should be exposed anyway? Is there a way of exposing it through configuration?

Thanks

henryContreras commented 5 years ago

I ran into the same problem, but instead I used the config variable in /node-media-server/node_http_server.js

app.all(['/api*'], (req, res, next) => { res.setHeader('Access-Control-Allow-Origin', this.config.http.allow_origin); next(); });

I share it in case someone find this useful https://github.com/henryContreras/Node-Media-Server/commit/e3b7c8e91cce08e9dbdeded670bb8cf58d9f4fa2