Reputation: 55779
I have created a proxy to run locally so I have control over inbound requests.
'use strict';
var express = require('express');
var request = require('request');
var app = express();
var apiUrl = 'http://my-service/resource';
var port = parseInt(process.env.APP_PORT || '23048');
var appName = 'forwarding-proxy';
app.use('*', function(req, res) {
var x = request(apiUrl);
req.pipe(x);
x.pipe(res);
});
app.listen(port);
console.log('Started at http://localhost:' + port + '/' + appName + '/');
How can I modify this to inject the following header to responses?
Access-Control-Expose-Headers: X-total-count, X-page-count
Upvotes: 0
Views: 105
Reputation: 10470
You can try this:
var x = request(apiUrl);
req.pipe(x).on('response', function(res) {
res.headers['Access-Control-Expose-Headers'] = "X-total-count, X-page-count ";
}).pipe(res);
With some more explanation on your specific issue, I may be able to assist you in better alternatives.
Upvotes: 1