简体   繁体   English

为什么我的节点服务器无法从我的节点服务器获得任何响应到 chrome 浏览器,但它在邮递员上工作正常?

[英]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.

相关问题 我的服务器在 prot 6666 上运行,我可以从 postman 获得响应,但是当我在浏览器上打开 localhost:6666 时,它说无法访问 - 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 我无法取回我的数据,Post 功能工作正常,经邮递员测试 - I can't get my data back, The Post function is working fine, tested with postman 我的jQuery .hover正常工作,但无法获得.click的工作 - My jQuery .hover's are working fine, but I can't get .click to work 如何从 Chrome 浏览器中的请求中获取响应数据? - How can I get the response data from a request in Chrome browser? 我无法从服务器获得响应 - I can't get a response from the server 为什么我无法在 Google Chrome 中运行我的任何 JavaScript? - Why can't I run any of my JavaScript in Google Chrome? 为什么我不能在运行由Openshift托管的Node.js + Websocket的服务器上获取连接客户端的IP地址(使用WebSocket-Node) - Why can't I get the connecting client's ip address on my server running Node.js + Websocket hosted by Openshift (Using WebSocket-Node) 为什么我无法将 SQL Server 连接到我的节点 js - Why Can't I connect SQL Server to my node js 为什么无法连接到节点服务器? - Why can't I connect to my Node server? 为什么我没有得到任何回应? - Why I don't get any response?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM