Express 如何在不传输编码的情况下代理数据:分块?
我有一个基于express.js的代理,用于代理通过Serverless和AWS Lambda部署到同一域中的不同应用:Express 如何在不传输编码的情况下代理数据:分块?,express,aws-api-gateway,next.js,Express,Aws Api Gateway,Next.js,我有一个基于express.js的代理,用于代理通过Serverless和AWS Lambda部署到同一域中的不同应用: const serverless = require('serverless-http'); const httpProxy = require('http-proxy'); const express = require('express'); const app = express(); const proxy = httpProxy.createProxyServ
const serverless = require('serverless-http');
const httpProxy = require('http-proxy');
const express = require('express');
const app = express();
const proxy = httpProxy.createProxyServer();
proxy.on('proxyReq', (proxyReq) => {
proxyReq.setHeader('X-Projects-Router-Proxy-Out', true);
});
app.get(['/:project', '/:project/*'], (req, res) => {
const { project } = req.params;
const rest = req.params[0];
const url = `https://${project}.${process.env.DEPLOY_STAGE}.example.com/${project}`;
req.url = rest ? `/${rest}` : '';
proxy.web(req, res, {
target: url,
xfwd: false,
toProxy: true,
changeOrigin: true,
secure: true,
});
});
module.exports.handler = serverless(app);
这在大多数情况下都很有效,但我现在遇到了麻烦。我代理的其中一个项目是next.js应用程序,\u next
目录的资产都返回502坏网关错误,因为AWS API网关不支持分块编码(我使用它来处理所有请求)。根据一些人的说法,我应该能够删除传输编码:chunked
头
这很好,只是这些资产上没有发送传输编码头,所以删除它并不能解决问题。我认为也没有发送内容长度头,因此默认情况下它假定chunked
。如何添加内容长度标题?有没有其他办法来解决这个问题