代理不适用于快递。好像没有定义
Proxy does not work on express. Seems it's not defined
我正在尝试使用 Node.js 上的以下教程在单个服务器上配置多个应用程序:
然后在下面的代码中,代理似乎没有定义: "TypeError: proxy is not a function" 但是代理应该在快递上定义,我说的对吗?它甚至在 express reference
const express = require('express');
const proxy = require('http-proxy-middleware');
const {routes} = require('./config.json');
const app = express();
for(route of routes){
app.use(
route.route,proxy({
target: route.address,
pathRewrite: (path, req) => {
return path.split('/').slice(2).join('/');
}
})
);
}
app.listen(1000,()=>{
console.log('Proxy listening on port 1000');
});
请检查http-proxy-middleware
的版本。对于v0.x,你应该这样使用它:
var proxy = require('http-proxy-middleware');
对于v1.x.x,你应该这样使用:
const { createProxyMiddleware } = require('http-proxy-middleware');
我正在尝试使用 Node.js 上的以下教程在单个服务器上配置多个应用程序:
然后在下面的代码中,代理似乎没有定义: "TypeError: proxy is not a function" 但是代理应该在快递上定义,我说的对吗?它甚至在 express reference
const express = require('express');
const proxy = require('http-proxy-middleware');
const {routes} = require('./config.json');
const app = express();
for(route of routes){
app.use(
route.route,proxy({
target: route.address,
pathRewrite: (path, req) => {
return path.split('/').slice(2).join('/');
}
})
);
}
app.listen(1000,()=>{
console.log('Proxy listening on port 1000');
});
请检查http-proxy-middleware
的版本。对于v0.x,你应该这样使用它:
var proxy = require('http-proxy-middleware');
对于v1.x.x,你应该这样使用:
const { createProxyMiddleware } = require('http-proxy-middleware');