bttmly / nba

Node.js client for nba.com API endpoints
MIT License
710 stars 180 forks source link

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

Closed petienne1 closed 5 years ago

bttmly commented 5 years ago

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.

petienne1 commented 5 years ago

Hi Nick,

Thanks for getting back to me. Have you tried any other packages or any other options to retrieve NBA API data?

Thanks, Pierry

On Thu, Jul 18, 2019 at 5:41 PM Nick Bottomley notifications@github.com wrote:

Well, you can try running Chrome without web security https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome. 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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bttmly/nba/issues/69?email_source=notifications&email_token=AFARHU7EHNGWAYVR6DJCWIDQADPQ7A5CNFSM4IEVK4UKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2J37XY#issuecomment-512999391, or mute the thread https://github.com/notifications/unsubscribe-auth/AFARHU3A7EEZDSZJK4V6GKDQADPQ7ANCNFSM4IEVK4UA .

bttmly commented 5 years ago

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.