IJMacD / newsmap-js

NewsMap JS - JS implementation of the defunct newsmap.jp
http://newsmap.ijmacd.com/
99 stars 36 forks source link

How to set 'API_ROOT' properly? #16

Closed zczcs12 closed 2 years ago

zczcs12 commented 3 years ago

Hi, please forgive me if this is a novice question, but that is exactly what I am when it comes to javascript.

When I run the project (npm start) on my local machine, I get a stack of errors like the following:

image

It appears my requests are not being sent to news.google.com but to localhost. Can you tell me what I need to change please?

IJMacD commented 3 years ago

Hi Ben,

Sorry it's taken a while to get back to this issue.

The reason the JS app can't communicate directly with the Google News servers is due to CORS.

The workaround is to run your own proxy server. I've included a very simple proxy in server.js in the root of the project. To use use it, in a second terminal window simply run:

node ./server.js

Then you'll have the debug server and the proxy server both running and they should be able to communicate with each other and relay news data from the Google News servers.

IJMacD commented 2 years ago

With the latest version of react-scripts a simpler proxy setup is possible.

In dev mode:

Just run npm start to proxy Google News by default

In prod mode

  1. Set environment variable REACT_APP_API_ROOT to RSS feed API server or your own proxy to Google News.
  2. Run npm run build