newsmap-js icon indicating copy to clipboard operation
newsmap-js copied to clipboard

How to set 'API_ROOT' properly?

Open zczcs12 opened this issue 3 years ago • 1 comments

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?

zczcs12 avatar Dec 23 '20 10:12 zczcs12

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 avatar Jan 12 '21 03:01 IJMacD

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

IJMacD avatar Sep 26 '22 14:09 IJMacD