fut*_*ime 5 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.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);
Run Code Online (Sandbox Code Playgroud)
这对于大多数事情来说都非常有效,但我现在遇到了麻烦。我代理的项目之一是 next.js 应用程序,该_next目录的资产都返回 502 Bad Gateway 错误,因为 AWS API Gateway(我用来处理所有请求)不支持分块编码。根据一些谷歌 结果,我应该能够删除标题transfer-encoding: chunked。
这很好,但这些资产上没有发送传输编码标头,因此删除它并不能解决问题。我认为也没有发送内容长度标头,因此chunked默认情况下是这样。如何添加内容长度标头?还有其他方法可以解决这个问题吗?
| 归档时间: |
|
| 查看次数: |
737 次 |
| 最近记录: |