简体   繁体   中英

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. I got this in 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.

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. Firefox has canceled the request for your protection.

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.

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. Here's how:

(0) Select and copy the following preference name

network.security.ports.banned.override (1) In a new tab, type or paste about:config in the address bar and press 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

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. No spaces. Then click OK.

If the above-listed preference does not exist:

(4) right-click anywhere on the page and choose New > String

(5) In the preference name dialog, paste the name you coped and click OK

(6) In the preference value dialog, type in the port number you need to allow, then click OK.

Or choose a differnt port

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM