UNPKG

vyndra-js

Version:

Micro Node.js framework with routing, ORM, decorators, and automatic DI

26 lines (25 loc) 715 B
export function enhanceResponse(res) { const enhanced = res; enhanced.status = function (code) { this.statusCode = code; return this; }; enhanced.json = function (data) { this.setHeader("Content-Type", "application/json"); this.end(JSON.stringify(data)); }; enhanced.send = function (data) { if (typeof data === "object") { this.setHeader("Content-Type", "application/json"); this.end(JSON.stringify(data)); } else { this.end(data); } }; enhanced.sendHtml = function (data) { this.setHeader("Content-Type", "text/html"); this.end(data); }; return enhanced; }