简体   繁体   English

当我制作 setupProxy.js 时,本地主机拒绝连接

[英]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.

相关问题 Typescript setupProxy.js 带有自定义 webPack 配置 - Typescript setupProxy.js whit custom webPack config Node.js localhost:3000 拒绝连接 - Node.js localhost:3000 refuses to connect setupProxy.js 路径在使用 http 代理中间件的 reactjs 应用程序中无法识别 - setupProxy.js path are not recognizing in reactjs application using http proxy middleware 为什么我的后端代理(使用 setupProxy.js 文件设置)没有代理到正确的端口? - Why is my backend proxy (setup using a setupProxy.js file) not proxying to the right port? “Localhost 拒绝连接”与 npm 启动 - “Localhost refuses to connect” with npm start 尝试连接到节点 js 服务器时等待 localhost - Waiting for localhost when trying to connect to node js server 如何让 React setupProxy 与 express.js 一起正常工作 - How to get React setupProxy to work correctly with express.js Localhost拒绝来自Javascript的连接 - Localhost refuses connection from Javascript Kafka.JS 拒绝连接 <<[BrokerPool] 无法连接到种子代理,正在尝试列表中的另一个代理>> - Kafka.JS refuses to connect <<[BrokerPool] Failed to connect to seed broker, trying another broker from the list>> 尝试连接到 node.js 中的 localhost:4000/addProduct 时出现“无法获取 /” - “Cannot GET /” when trying to connect to localhost:4000/addProduct in node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM