[英]My server is running on prot 6666, I can get response from postman, but when I open localhost:6666 on browser, it says cannot be reached
[英]Why i can't get any response from my node server to chrome browser but it's working fine on postman?
这是一个反应项目。 我在服务器端使用 multer(它是一个 REST API)并且我在 postman 中获取文件,但是在浏览器中它不起作用,我尝试了简单的 get 请求在 postman 中工作但不在浏览器中。 我在 chrome 中得到了这个:
无法访问此站点 http://localhost:6000/images/ad.jpg 的网页可能暂时关闭,或者它可能已永久移动到新网址。
我在火狐中收到了这条消息
此地址受限制
此地址使用网络端口,该端口通常用于 Web 浏览以外的目的。 Firefox 已取消保护您的请求。
import express from "express" ;
import cors from "cors" ;
const app =express() ;
const __dirname = path.dirname(fileURLToPath(import.meta.url));
dotenv.config() ;
app.use(express.json({limit:"30mb",extended:true})) ;
app.use(express.urlencoded({limit:"30mb",extended:true})) ;
app.use(morgan("common")) ;
app.use(helmet()) ;
app.use("/api/user/",userRoute) ;
app.use("/api/auth/",userAuth) ;
app.use("/api/posts/",postRoute) ;
const storage =multer.diskStorage({
destination:(req,file,cb) =>{
cb(null,"public/images")
} ,
filename:(req,file,cb)=>{
cb (null,file.originalname)
}
})
const upload = multer({storage}) ;
app.post("/api/upload/",upload.single("file"), (req,res)=>{
try {
return res.status(200).json("file uploaded successfully")
} catch (error) {
console.log(error.message)
}
})
const ClusterURL=process.env.CLUSTER_URL ;
const PORT=process.env.PORT || 6000 ;
mongoose.connect(ClusterURL,{useNewUrlParser:true,useUnifiedTopology:true,useFindAndModify:false,useCreateIndex:true})
.then(()=>app.listen(PORT,()=>console.log(`Successfully connected to port ${PORT}`)))
.catch((error)=>{console.log(error.message)}) ;
app.use('/images' , express.static(path.join(__dirname, 'public/images')));
app.get("/bitch",(req,res)=>{
res.json("yo bitch") ;
}); ```
**i should get the images files in the browser in this address http://localhost:6000/images/ad.jpg**
6000
属于受限端口列表。
您可以根据此描述允许(我不推荐)此端口
您可以使用 about:config 创建首选项并允许 Firefox 阻止的端口号。 就是这样:
(0) 选择并复制以下首选项名称
network.security.ports.banned.override (1) 在新选项卡中,在地址栏中键入或粘贴 about:config,然后按 Enter/Return。 单击按钮承诺要小心。
(2) 在列表上方的搜索框中,键入或粘贴端口并在过滤列表时暂停
如果上面列出的偏好存在:
(3) 双击它并在列表末尾添加一个逗号,后跟您需要允许的端口号。 没有空间。 然后单击确定。
如果上面列出的偏好不存在:
(4)在页面任意位置右击,选择New > String
(5) 在首选项名称对话框中,粘贴您处理的名称,然后单击确定
(6) 在首选项值对话框中,输入您需要允许的端口号,然后单击确定。
或者选择不同的端口
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.