ERR_CONNECTION_REFUSED 当我尝试从连接到同一 wifi 网络的移动设备访问笔记本电脑本地主机上的服务器 运行 时出错
ERR_CONNECTION_REFUSED error when i try to access the server running on localhost on laptop from my mobile devise connected to same wifi network
我想从我的 android phone 访问我使用 node.js 构建的服务器。我的服务器 运行 在本地主机端口 80 上,我的笔记本电脑和移动设备连接到同一个 wifi 网络。
我尝试关闭 windows defender 防火墙,但没有用。
在我的移动设备浏览器中,我使用 link 作为
向我的服务器发出请求
laptop_ip_address:port_no/home
但是没有用。
我的浏览器出现 ERR_CONNECTION_REFUSED 错误。
我不想使用 ngrok。
我该怎么办?
这是我的服务器代码
const express=require("快递")
const app=express()
app.get("/",(req,res)=>{
res.status(200).send("<h1>hiiii</h1><a href='/home'>hii</a>")
})
app.get("/home",(req,res)=>{
res.status(200).send("<h1>yooo</h1>")
})
app.listen(80,()=>{
console.log("App is running");
})
添加cors模块后再试。这可能有助于解决问题。
const cors=require('cors')
const app=express()
app.use(cors);
app.get("/",(req,res)=>{
res.status(200).send("<h1>hiiii</h1><a href='/home'>hii</a>")
})
app.get("/home",(req,res)=>{
res.status(200).send("<h1>yooo</h1>")
})
app.listen(80,()=>{
console.log("App is running");
})
我想从我的 android phone 访问我使用 node.js 构建的服务器。我的服务器 运行 在本地主机端口 80 上,我的笔记本电脑和移动设备连接到同一个 wifi 网络。
我尝试关闭 windows defender 防火墙,但没有用。
在我的移动设备浏览器中,我使用 link 作为
laptop_ip_address:port_no/home
但是没有用。
我的浏览器出现 ERR_CONNECTION_REFUSED 错误。
我不想使用 ngrok。
我该怎么办?
这是我的服务器代码
const express=require("快递")
const app=express()
app.get("/",(req,res)=>{
res.status(200).send("<h1>hiiii</h1><a href='/home'>hii</a>")
})
app.get("/home",(req,res)=>{
res.status(200).send("<h1>yooo</h1>")
})
app.listen(80,()=>{
console.log("App is running");
})
添加cors模块后再试。这可能有助于解决问题。
const cors=require('cors')
const app=express()
app.use(cors);
app.get("/",(req,res)=>{
res.status(200).send("<h1>hiiii</h1><a href='/home'>hii</a>")
})
app.get("/home",(req,res)=>{
res.status(200).send("<h1>yooo</h1>")
})
app.listen(80,()=>{
console.log("App is running");
})