bttmly / nba

Node.js client for nba.com API endpoints

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I work around the CORS restriction so that I can test my site on my browser locally?

petienne1 opened this issue · comments

How can I work around the CORS restriction so that I can test my site on my browser locally?

Well, you can try running Chrome without web security. However, since the CORS policy makes this package unusable from the browser except in this case, I haven't verified that the current version can be packaged for the browser using e.g. webpack. Given the CORS constraints, I'm no longer aiming to support web browsers with this package.

The CORS issue will generally prevent any browser-based application from communicating directly with nba.com, whether it uses this package or not. An npm search shows a few interesting packages, none of which I've vetted thoroughly. In particular, basketball-reference-js looks interesting since it uses basketball-reference.com rather than nba.com.

As for using this package, there are a few possible work arounds, but it depends on the specific application.

– If you are doing data analysis, you can pull the data once with a Node.js script that uses this library. Then you can embed the data directly in a web page, or serve it from a web server of your own.

– If you need live access to NBA.com data from the browser, the simplest option I can think of is to run a web server that will accept requests from this library and forward them to NBA.com, then send the result back down to the web browser. That approach would require some significant code changes to this library, since the URLs are hard coded at the moment.