Angular 2/4 -- Glitch.com compatibility with HTTP requests


#1

Hi–

I am running into a problem that seems to be related specifically to Angular 2 and Glitch. I found a workaround, but I thought I would post here to see if someone had insight.

When making HTTP requests via an Angular app (hosted locally as of now, and then sending to the url of the Glitch project), I can’t seem to send anything in the body of the request. The request comes through just fine, and I can specify any of the other “RequestOptions”, but no matter what I do, the body is always just an empty object.

For now, I am passing the data I need as the value attached to the “search” parameter, and then pulling it out of there (using req._parsedUrl.query), but that seems like a messy approach.

Previously, I had a simple version of the app hosted entirely on Glitch, and was using jQuery to send the requests, and this worked just fine. This is what makes me think there is something specific with how Angular2 and Glitch are talking to each other. Or something weird about body-parser?

I am still very new to backend stuff, and honestly to coding in general, so there may be some very obvious thing I am overlooking.

Any insight would be greatly appreciated. Thanks.

(here are some code snippets just in case:)

This is from an Angular “service”:

	website = website.replace(/https/, "http") + "&pagesize=100"; //website is passed into the argument from a form in the HTML. This is my weird method of dealing with CORS stuff.
  	let headers = new Headers({'Content-Type': 'application/json'})
  	let reqOpts = new RequestOptions({
  		url: "https://exultant-runner.glitch.me/getpaperlist",
  		method: RequestMethod.Get,
  		body: website,
  		headers: headers});
  	let req = new Request(reqOpts)

  	return this.http.request(req);

It sends this request to my server on Glitch, where, for this endpoint right now, the code is basically just to log the request to the console. console.log(req.body) always gives {} as output. But, like I said, I’m able to set headers, params, etc. however I need. I do have the body-parser required on the server, and am using it without issue in other places.


#2

I think this is caused by a bug we introduced recently. I’m planning to deploy the fix today.


#3

@Tim, That’s an interesting mix of good and bad timing on my part.

I’ll keep an eye out and see if anything changes. For now, I’ll keep with the workaround. Thanks.


#4

The changes to fix this bug were tangled up with some more complicated changes, so they didn’t get released until this morning. You should now be able to post a JSON body again.


#5

Great! Thanks for updating me. I’ll make those changes now.