[英]Why i can't get any response from my node server to chrome browser but it's working fine on postman?
It's a react project.这是一个反应项目。 I use multer on the server side (it's a REST API) and i get the files in postman , but in browser it's not working , and i tried simple get request works in postman but not in the browser.我在服务器端使用 multer(它是一个 REST API)并且我在 postman 中获取文件,但是在浏览器中它不起作用,我尝试了简单的 get 请求在 postman 中工作但不在浏览器中。 I got this in chrome :我在 chrome 中得到了这个:
This site can't be reachedThe webpage at http://localhost:6000/images/ad.jpg might be temporarily down or it may have moved permanently to a new web address.无法访问此站点 http://localhost:6000/images/ad.jpg 的网页可能暂时关闭,或者它可能已永久移动到新网址。
I got this message in fire fox我在火狐中收到了这条消息
This address is restricted此地址受限制
This address uses a network port which is normally used for purposes other than Web browsing.此地址使用网络端口,该端口通常用于 Web 浏览以外的目的。 Firefox has canceled the request for your protection. 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
belongs to a list of restricted ports. 6000
属于受限端口列表。
You can either allow (which I wouldn't recommend) this port based on this description您可以根据此描述允许(我不推荐)此端口
How to allow a restricted port?如何允许受限端口?
You can create a preference using about:config and allow the port number which Firefox is blocking.您可以使用 about:config 创建首选项并允许 Firefox 阻止的端口号。 Here's how:就是这样:
(0) Select and copy the following preference name (0) 选择并复制以下首选项名称
network.security.ports.banned.override (1) In a new tab, type or paste about:config in the address bar and press Enter/Return. network.security.ports.banned.override (1) 在新选项卡中,在地址栏中键入或粘贴 about:config,然后按 Enter/Return。 Click the button promising to be careful.单击按钮承诺要小心。
(2) In the search box above the list, type or paste ports and pause while the list is filtered (2) 在列表上方的搜索框中,键入或粘贴端口并在过滤列表时暂停
If the above-listed preference exists:如果上面列出的偏好存在:
(3) Double-click it and add a comma to the end of the list followed by the port number you need to allow. (3) 双击它并在列表末尾添加一个逗号,后跟您需要允许的端口号。 No spaces.没有空间。 Then click OK.然后单击确定。
If the above-listed preference does not exist:如果上面列出的偏好不存在:
(4) right-click anywhere on the page and choose New > String (4)在页面任意位置右击,选择New > String
(5) In the preference name dialog, paste the name you coped and click OK (5) 在首选项名称对话框中,粘贴您处理的名称,然后单击确定
(6) In the preference value dialog, type in the port number you need to allow, then click OK. (6) 在首选项值对话框中,输入您需要允许的端口号,然后单击确定。
Or choose a differnt port或者选择不同的端口
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.