简体   繁体   English

为什么 axios 试图连接端口 80 而不是 8080?

[英]Why is axios trying to connect on port 80 and not 8080?

I am running a Node/Express back-end with a vue front-end on a Windows 10 machine.我在 Windows 10 机器上运行带有vue前端的 Node/Express 后端。 I did install iisnode because I thought I would serve server.js using IIS, but at the moment I am in development and would like to leave IIS out of it.我确实安装iisnode ,因为我认为我会使用 IIS 为server.js提供服务,但目前我正在开发中,并希望将 IIS 排除在外。

However, when I make a production build of the website and run node./dist/server.js , the Node/Express server runs on port 8080 and the homepage loads fine.但是,当我对网站进行生产构建并运行node./dist/server.js时,Node/Express 服务器在port 8080上运行,并且主页加载正常。

When I go to a product page that makes an axios call, I am getting an error that:当我 go 到进行axios调用的产品页面时,我收到一个错误:

Error: connect ECONNREFUSED 127.0.0.1:80
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1137:16) {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 80,
  config: {
    url: '/api/int/v1/product/10800',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.21.1'
    },
...... // more stuff here
isAxiosError: true //<== is an axios issue?

I don't understand why it is trying to connect on port 80 instead of just going to http://localhost:8080/api/int/v1/product/10800我不明白为什么它试图连接端口 80 而不是仅仅去http://localhost:8080/api/int/v1/product/10800

server.js does this: server.js这样做:

const PORT = process.env.PORT || 8080;
server.listen(PORT, () => {
    console.log(`Server is listening on port ${PORT}`);
});

And I even set the port when running the build script like this:我什至在运行构建脚本时设置了port ,如下所示:

"build:server": "cross-env PORT=8080 NODE_ENV=production webpack --config build/webpack.server.config.js"

In the console log it even says Server is listening on port 8080console日志中,它甚至说Server is listening on port 8080

You need to configure the axios BASE_URL, defining the port there eg:您需要配置 axios BASE_URL,在那里定义端口,例如:

import axios from 'axios'
axios.defaults.baseURL = 'http://localhost:8080';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Windows Azure中将公用端口80连接到VM端口8080 - How to connect public port 80 to VM port 8080 in windows azure 将端口从80和443转发到8080 - Forward Port from 80 & 443 to 8080 使用NGINX将端口80转发到8080 - Forwarding port 80 to 8080 using NGINX 端口8080或80上的移动网络中的WebSocket连接失败 - WebSocket connection failed in mobile network on port 8080 or 80 Axios 错误:连接 ECONNREFUSED 127.0.0.1:80 - Axios Error: connect ECONNREFUSED 127.0.0.1:80 为什么我在CentOS中使用node.js无法连接8080端口? - Why I can't connect port 8080 using node.js in CentOS? 尝试从主机连接到端口8080时,运行react.js的Linux容器(xenail)使我无法连接消息 - Linux Container (xenail) running react.js gives me Unable to Connect message when trying to connect to port 8080 from host 尝试使用 axios 将后端连接到前端,但不确定为什么数据未呈现 - trying to connect backend to frontend using axios but unsure why the data is not rendering 测试客户端是否可以使用端口80,443,843连接到WebSockets - Testing if client can connect to WebSockets with port 80, 443, 843 Azure Ubuntu VM应用程序只能在端口80上连接 - Azure Ubuntu VM application only able to connect on port 80
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM