[英]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 8080
在console
日志中,它甚至说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.