Json response class

pull/6/head
sundowndev 2018-08-30 14:24:11 +02:00
parent 394acf0091
commit 40cb7738f7
1 changed files with 19 additions and 0 deletions

19
src/JsonResponse.js Normal file
View File

@ -0,0 +1,19 @@
"use strict";
export default function JsonResponse() {
this.httpCode = 200;
this.headers = {'Content-Type': 'application/json'};
}
JsonResponse.prototype.init = function (app, res) {
// Enable json prettify
app.set('json spaces', 2);
// Set response headers
res.setHeader('Accept', 'application/json');
res.setHeader('Content-Type', 'application/json');
};
JsonResponse.prototype.send = function (res, code, response) {
return res.json(response);
};