XML GET request from client side to server is failing

Code can be found here

I had this working when I was previously using a flip server through my college, but after making adjustments to push to github and then Glitch, the request is now failing. I tried copying the fully updated project back onto the flip server, switched the urls in the client side js for Search and Popular News back to flip urls, and am now getting this error message:

/nfs/stak/users/ilardis/Projects/News-Aggregator - Copy/node_modules/express-handlebars/lib/express-handlebars.js:52
async getPartials (options) {
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions…js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/nfs/stak/users/ilardis/Projects/News-Aggregator - Copy/node_modules/express-handlebars/index.js:9:27)

Not sure if this is related to the Glitch GET request issue. Tried googling that error message and posted on stack overflow but could not find any solutions. Any help would be appreciated, and please let me know if I can provide any additional information. Thanks.

Hi silardi,

From reading your question I can’t tell which rabbit you’re chasing:

  • Getting it working on the “flip server”;
  • Getting it working on Glitch

When I visit your site on Glitch, it looks ok, but when I search, I can see a 404 in the DevTools:

GET https://shy-flaxen-fragrance.glitch.me/popular?timeRange=1 404 (Not Found)
(anonymous) @ popularNews.js:34

If you go direct to the /popular endpoint you’ll see the 404 response. Makes me think that it’s calling into your branch with the next(), maybe because the API request to NYT fails:

    } else {

…you can check your logs to verify.


About your original query. I guess the arrows ^^^ are supposed to be under getPartials. This usually happens because the async keyword wasn’t expected. I don’t know how you’re building your JS, I would have thought async/await is standard now in all build tools and browsers.

The only SO answer I could find is this, but it doesn’t look relevant to what you’re doing:

Hope this helps a little.



Hi @SteGriff ,

Thanks for trying to help. I fixed the async error on the flip server by re-installing my node_modules, but I am still stuck on the GET request issue as I noted above (this is the rabbit I’m chasing).

You are correct in that the next() branch is being activated which is why I am receiving the 404 response (401 is also being printed in Glitch logs), but I still have not been able to figure out what the issue is. My code works perfectly when using flip servers, but when I change the XHR request URL from http://flip2.engr.myschool.edu:4244/popular?timeRange=
to the Glitch URL
the request is failing and I am getting a 404. I just don’t understand what is causing the issue since it works when using the flip URL. I should also note that I started a new Glitch project (code) which is why the URL is different than in my initial post.

The overall flow of the app is that a user clicks submit on either the popular news or search page, which makes a request to my server code, which then sends a request to the New York Times API to pull the info, and then it sends that info back to the client side (in order to protect the identity of my API key).

Any additional insights would be greatly appreciated.

1 Like

In case if you don’t know, Glitch is blocking their pinging service, which caused non-User agent request will rejected to 403 error.

So, You must provide User-agent headers before request it.

Hi @Yonle - thanks for replying. Since I am seeing 401 in the Glitch logs, and not 403, do you still think that this could be the issue? If so, are you referring to implementing this? Unfortunately I have no experience with User-agent headers.

1 Like

Could you try opening the Glitch project terminal (ctrl+shift+x) and using curl to make the nytimes request on the command line? That’ll save you the trouble of hacking up your project code with a bunch of debug logging.

Glitch gets used by all sorts of people with all sorts of opinions on what is abusive, so maybe nytimes is not on good terms with the Glitch servers at this time.

Hi @wh0, I appreciate the reply. I gave that a shot and it returned the html of my 404.handlebars view. I also tried this out on Heroku and got the same 404 response. That could be indicative of an issue on my end, although it also just might mean that nytimes may not be on good terms with Heroku as well.

wait, I mean to curl api.nytimes.com directly, not to go through your project:

curl "https://api.nytimes.com/svc/mostpopular/v2/viewed/1.json?api-key=$API_KEY"
1 Like

Wow I should have realized that. I’m new to web development, sorry! I just tried it and received the correct response, so that is not the issue.

@SteGriff @Yonle @wh0 thanks again for trying to help - just wanted to let you know that I figured out the issue. I had incorrectly assumed that the contents of my .env file (my API key) would be automatically added to glitch, but just discovered that I needed to manually add the api key variable into the Glitch .env file. Can’t believe I didn’t check that until now.