Front end of the Slack clone application.

json.js 683B

123456789101112131415161718192021222324252627282930
  1. var jsonParse = require("safe-json-parse")
  2. var body = require("./index.js")
  3. var parseArguments = require("./parse-arguments.js")
  4. module.exports = jsonBody
  5. function jsonBody(req, res, opts, callback) {
  6. var args = parseArguments(req, res, opts, callback)
  7. req = args.req
  8. res = args.res
  9. opts = args.opts
  10. callback = args.callback
  11. if (!callback) {
  12. return jsonBody.bind(null, req, res, opts)
  13. }
  14. var parse = opts.JSON ? opts.JSON.parse : jsonParse
  15. var reviver = opts.reviver || null
  16. body(req, res, opts, function (err, body) {
  17. if (err) {
  18. return callback(err)
  19. }
  20. parse(body, reviver, callback)
  21. })
  22. }