[英]Localhost refuses to connect when I make setupProxy.js
I made my setupProxy.js to deal with a CORS issue:我让 setupProxy.js 处理 CORS 问题:
const proxy = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
proxy('/myUrl', {
target: 'http://localhost:8090',
changeOrigin: true
})
)
};
After I made it and run 'npm start' again, my browser says that localhost refuses to connect.在我成功并再次运行“npm start”之后,我的浏览器说 localhost 拒绝连接。 If I delete setupProxy.js, I can connect to localhost, but the CORS policy blocks to connect with backend server.
如果我删除 setupProxy.js,我可以连接到 localhost,但 CORS 策略阻止连接到后端服务器。
Do you have any idea to connect to frontend, still using the setupProxy.js?您是否有任何想法连接到前端,仍然使用 setupProxy.js?
You can try this: createProxyMiddleware你可以试试这个: createProxyMiddleware
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
createProxyMiddleware('/myUrl', {
target: 'http://localhost:8090',
changeOrigin: true,
})
);
};
https://stackoverflow.com/a/60354374/11652543 https://stackoverflow.com/a/60354374/11652543
See that you have spelled the name of setupProxy.js well that solved the problem for me.看到您已经很好地拼写了 setupProxy.js 的名称,这为我解决了问题。 If that does not work.
如果这不起作用。 Copy and pase the fb's code the way it is into the setupProxy.js Code can be found here
将 fb 的代码复制并粘贴到 setupProxy.js 中代码可以在这里找到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.