Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev server could show http post body in the ternimal #124

Open
dotnetCarpenter opened this issue May 17, 2016 · 1 comment
Open

Dev server could show http post body in the ternimal #124

dotnetCarpenter opened this issue May 17, 2016 · 1 comment

Comments

@dotnetCarpenter
Copy link
Member

Similar to GET request, a POST request could trigger a logger that displays the content of the body in the terminal for quick debugging.

@dotnetCarpenter
Copy link
Member Author

This code should do the trick:

function logPOST() { // logPOST is NOT thread safe, e.i. multiple request can write to body
  var body = []
  return function(request, response) {
    if(request.method === "POST") {
      console.log("Recieved a POST request. Collecting data...")
      request.on("data", function(chunk) {
        body.push(chunk)
      }).on("end", function() {
        console.log( Buffer.concat(body).toString() )
        body.splice(0, body.length) // empty body array
      })
    }
  }
}

Now I just need to write a test....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant