最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

代理不服务于获取请求:http

IT培训 admin 2浏览 0评论

代理不服务于获取请求:http

我使用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: '',
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'));

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

回答如下:

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

代理不服务于获取请求:http

我使用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: '',
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'));

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

回答如下:

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

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论