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