MCPcopy Create free account
hub / github.com/avoidwork/tenso / render

Method render

src/tenso.js:302–329  ·  view source on GitHub ↗

* Renders the response based on the accepted content type * @param {Object} req - Request object * @param {Object} res - Response object * @param {*} arg - Data to be rendered * @returns {*} The rendered response

(req, res, arg)

Source from the content-addressed store, hash-verified

300 * @returns {*} The rendered response
301 */
302 render (req, res, arg) {
303 if (arg === null) {
304 arg = NULL;
305 }
306
307 const accepts = (req.parsed.searchParams.get(FORMAT) || req.headers.accept || res.getHeader(HEADER_CONTENT_TYPE)).split(COMMA);
308 let format = EMPTY,
309 renderer, result;
310
311 for (const media of accepts) {
312 const lmimetype = media.replace(mimetype, EMPTY);
313
314 if (this.renderers.has(lmimetype)) {
315 format = lmimetype;
316 break;
317 }
318 }
319
320 if (format.length === INT_0) {
321 format = this.mimeType;
322 }
323
324 renderer = this.renderers.get(format);
325 res.header(HEADER_CONTENT_TYPE, format);
326 result = renderer(req, res, arg, this.webroot.template);
327
328 return result;
329 }
330
331 /**
332 * Registers a renderer for a specific media type

Callers 6

testRequestResponseFunction · 0.80
testJsonSerializationFunction · 0.80
testRequestProcessingFunction · 0.80
testMemoryLeaksFunction · 0.80
testHypermediaMemoryFunction · 0.80
testMemoryPressureFunction · 0.80

Calls 1

headerMethod · 0.80

Tested by

no test coverage detected