要通过 获取请求body: <json>,您需要使用.use(express.json())
文本也一样。.use(express.text())
对于 xml,您已经需要包含库express-xml-bodyparser,.use(xmlparser())
是否可以.use(<>)在没有说明的情况下以某种方式接受任何类型的紧身连衣裤?
createProxyServer() {
const logger = new ConsoleLoggerService('proxy-server');
const proxy = httpProxy.createProxyServer({ changeOrigin: true });
const app = express();
app.all('*', (req, res, next) => {
logger.log(`Got request to ${req.path}, method=${req.method} `);
next();
});
registerServiceController(app);
app.all('*', async (req, res, next) => {
const { path } = req;
const proxyPath = findProxyPath(path);
const proxyHost = proxyMap[proxyPath];
if (proxyHost) {
logger.log(`Path [${path}] will be proxying to [${proxyHost}] host`);
proxy.web(req, res, {
target: {
protocol: 'https:',
host: proxyHost,
port: 443,
},
});
} else {
logger.error(`Proxy mapping for [${path}] not found, request not proxied`);
}
next();
})
.use(express.json())
.use(express.text())
.use(express.raw({ type: 'application/pdf', limit: '10mb' }))
.use(xmlparser())
.all('*', async (req, res, next) => {
const { path } = req;
const proxyPath = findProxyPath(path);
const proxyHost = proxyMap[proxyPath];
await ProxyStorageService.saveRequest(req, proxyHost);
});
app.listen(PORT);
logger.log(`Server is listening on port ${PORT}`);
}
自然地... bodyParser.json() 之类的只是简单地返回一个普通的 express handlerFunction(req, res, next) ,你可以随意包装它。
索引.js
测试索引.http