【问题标题】:proxy not serving for get request : http-proxy-middleware代理不为获取请求服务:http-proxy-middleware
【发布时间】:2017-02-14 17:27:55
【问题描述】:

我正在使用 http-proxy-middleware 对应用程序进行反向代理,以避免在开发过程中出现 CORS。

以下是正在使用的 http-proxy-middleware 的设置。除了 GET 之外,我都收到了每种方法的响应。

设置:

路径:server/index.js

import express from 'express';
import path from 'path';
import webpack from 'webpack';
import webpackMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import webpackConfig from '../webpack.config.dev';
let proxy = require('http-proxy-middleware');
let app = express();
const compiler = webpack(webpackConfig);
app.use(webpackMiddleware(compiler, {
hot: true,
noInfo: true
}));
app.use(webpackHotMiddleware(compiler));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, './index.html'));
});
let options = {
target: 'https://example.com',
changeOrigin: true,
logLevel:'debug',
ws: true,
onProxyReq: function(proxyReq, req, res) {        
    //  log the req
    console.log('RAW REQUEST from the target', JSON.stringify(req.headers, true, 2));
},
onProxyRes: function (proxyRes, req, res) {

    //  log the response
    console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));
}
};
app.use(['/front_end_api/**'], proxy(options));
app.listen(3000, () => console.log('Running on localhost'));

如果我在这里做错了什么,请告诉我。

【问题讨论】:

    标签: node.js reactjs reverse-proxy http-proxy-middleware


    【解决方案1】:

    尝试将您的代理移动到 webpack-dev-middleware 之前。 http-proxy-middleware 存在问题,可能与您所看到的有关。 https://github.com/chimurai/http-proxy-middleware/issues/199

    【讨论】:

      猜你喜欢
      • 2017-08-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2021-04-08
      • 2023-03-26
      • 2020-03-02
      相关资源
      最近更新 更多