0
개발 중에 CORS를 피하기 위해 응용 프로그램을 역방향 프록시하기 위해 http-proxy-middleware를 사용하고 있습니다.프록시가 get 요청을 처리하지 않습니다. http-proxy-middleware
다음은 사용중인 http-proxy-middleware의 설정입니다. GET을 제외한 각 방법에 대한 응답이 나타납니다.
설정 :
경로 : 서버 /하는 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'));
내가 여기서 뭔가 잘못을하고있는 중이 있으면 알려 주시기 바랍니다.