MCPcopy Create free account
hub / github.com/restify/node-restify / formatTodo

Function formatTodo

examples/todoapp/lib/server.js:39–51  ·  view source on GitHub ↗

* This is a nonsensical custom content-type 'application/todo', just to * demonstrate how to support additional content-types. Really this is * the same as text/plain, where we pick out 'task' if available

(req, res, body, cb)

Source from the content-addressed store, hash-verified

37 * the same as text/plain, where we pick out 'task' if available
38 */
39function formatTodo(req, res, body, cb) {
40 if (body instanceof Error) {
41 res.statusCode = body.statusCode || 500;
42 body = body.message;
43 } else if (typeof body === 'object') {
44 body = body.task || JSON.stringify(body);
45 } else {
46 body = body.toString();
47 }
48
49 res.setHeader('Content-Length', Buffer.byteLength(body));
50 return cb(null, body);
51}
52
53///--- Handlers
54

Callers

nothing calls this directly

Calls 1

cbFunction · 0.85

Tested by

no test coverage detected