Reputation: 1057
const app = require('express')();
const { createProxyMiddleware } = require('http-proxy-middleware');
app.all('*', createProxyMiddleware({ target: 'https://www.google.com/', changeOrigin: true
}));
const awsServerlessExpress = require('aws-serverless-express');
const server = awsServerlessExpress.createServer(app);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);
This is the code I am using. My requirement is to implement Reverse Proxy Server. The issue is I am getting following error in Browser:
GET http://127.0.0.1:3000/ net::ERR_CONTENT_DECODING_FAILED 200 (OK)
Server is sending the response properly but there is an issue with Compression.
I tried passing following Mime-types as a 3rd Parameter to createServer function:
const binaryMimeTypes = [
'application/javascript',
'application/json',
'application/octet-stream',
'application/xml',
'font/eot',
'font/opentype',
'font/otf',
'image/jpeg',
'image/png',
'image/svg+xml',
'text/comma-separated-values',
'text/css',
'text/html',
'text/javascript',
'text/plain',
'text/text',
'text/xml'
]
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
But had no luck.
Can anyone please help me out with this? Thanks in advance.
Upvotes: 0
Views: 1667
Reputation: 1057
I solved it by overriding the Accept-Encoding header:
app.all('*', (req, res, next) => {
createProxyMiddleware({ target: 'https://www.google.com/', changeOrigin: true,
onProxyReq: (proxyReq, req, res) => {
proxyReq.setHeader('Accept-Encoding', 'identity');
}
})(req, res, next);
});
This solution is not optimized. As this solution will send response un-compressed which will increase the response content length. But for now this solved my issue. I will update if I find any other solution.
Upvotes: 1