1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const xmlbuilder = require("xmlbuilder");
|
4 |
|
5 |
|
6 |
|
7 | class ContentNegotiationMiddleware {
|
8 | constructor(xmlRoot) {
|
9 | this.xmlRoot = xmlRoot;
|
10 | }
|
11 | getMiddleware() {
|
12 | const xmlRoot = this.xmlRoot;
|
13 | if (!xmlRoot) {
|
14 | return;
|
15 | }
|
16 | return (req, res, next) => {
|
17 | const xmlType = 'application/xml';
|
18 | if (xmlType === req.get('accept')) {
|
19 | const originalSend = res.send;
|
20 | res.send = function (...data) {
|
21 | const obj = {};
|
22 | obj[xmlRoot] = data[0];
|
23 | data[0] = xmlbuilder.create(obj).end();
|
24 | originalSend.apply(res, data);
|
25 | };
|
26 | res.header('content-type', xmlType);
|
27 | }
|
28 | next();
|
29 | };
|
30 | }
|
31 | }
|
32 | exports.ContentNegotiationMiddleware = ContentNegotiationMiddleware;
|
33 |
|
\ | No newline at end of file |