This one has me scratching my head a bit, only because I think i'm doing it right but it's still not correct, so I could be doing this all wrong.
response.setHeader('Content-Type', 'application/json'); -- started trying up here
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Headers", "X-Requested-With")
var purl = "/api/forums/users/"
if(request.url == purl && request.method == "POST"){
response.setHeader('Content-Type', 'application/json'); -- When i found out setting them up top didnt work, i tried to set them here
response.setHeader('Accept','application/json');
console.log("Request Recieved!")
var bufdat = []
request.on('data',function(chunk){
bufdat.push(chunk)
var data = Buffer.concat(bufdat).toString()
console.log(data)
})
The data that is received is a buffer, the object that comes out of it is suppose to look something like this : {name:"usersname"}.
using .toString() on the buffer, gives me name=username (in string format obv)
So, I read on this post here: Safely turning a JSON string into an object that to turn a string into an object, I would just simply use JSON.parse(string), however that isnt working.
So i'm trying to figure out if there is a second solution, I tried to set the content headers to accept JSON objects so my object would be stringified as '{name:'username'}', but I couldn't get that to work either. I'm just not sure what i'm doing wrong here.