MCPcopy Create free account
hub / github.com/expressjs/body-parser / createServer

Function createServer

test/json.js:967–985  ·  view source on GitHub ↗
(opts)

Source from the content-addressed store, hash-verified

965})
966
967function createServer (opts) {
968 const _bodyParser = typeof opts !== 'function'
969 ? bodyParser.json(opts)
970 : opts
971
972 return http.createServer(function (req, res) {
973 _bodyParser(req, res, function (err) {
974 if (err) {
975 res.statusCode = err.status || 500
976 res.end(req.headers['x-error-property']
977 ? err[req.headers['x-error-property']]
978 : ('[' + err.type + '] ' + err.message))
979 } else {
980 res.statusCode = 200
981 res.end(JSON.stringify(req.body) || typeof req.body)
982 }
983 })
984 })
985}
986
987function parseError (str) {
988 try {

Callers 1

json.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected