UNPKG

@sap/xsodata

Version:

Expose data from a HANA database as OData V2 service with help of .xsodata files.

44 lines (35 loc) 1.08 kB
'use strict'; const configuration = require('./../configuration'); exports.JsonSerializer = JsonSerializer; function JsonSerializer(context, bufferSize, code) { const self = this; self.context = context; self.request = context.request; self.response = context.response; self.bufferSize = bufferSize; self.buffer = ''; code = code || 200; const header = { 'Content-Type': context.payloadType + ';charset=utf-8', }; if (context.gModel) { const cacheControl = context.gModel.getSetting( 'content', 'cache-control' ); if (cacheControl) { header['cache-control'] = cacheControl; } } self.response.writeHead(code, header); } JsonSerializer.prototype.write = function (data) { if (this.context.mode === configuration.modes.development) { this.buffer += JSON.stringify(data, null, 4); } else { this.buffer += JSON.stringify(data, null, 0); } }; JsonSerializer.prototype.flush = function () { this.response.write(this.buffer); };