簡體   English   中英

Express.js公用文件夾內容僅在登錄時可用

[英]Express.js public folder content only available when logged in

我試圖通過http://<IP Address>:3000/image.jpg訪問公共目錄中的靜態圖像文件,並且該文件僅在登錄服務器后才可用。 我注銷后就得到

在“網絡”選項卡中而不是頁面中找不到GET 404:

 Error: Not Found
   at module.exports (<path>/app.js:48:15)
   at Layer.handle [as handle_request] (<path>/node_modules/express/lib/router/layer.js:82:5)
   at trim_prefix (<path>/node_modules/express/lib/router/index.js:271:13)
   at <path>/node_modules/express/lib/router/index.js:238:9
   at Function.proto.process_params (<path>/node_modules/express/lib/router/index.js:313:12)
   at <path>/node_modules/express/lib/router/index.js:229:12
   at Function.match_layer (<path>/node_modules/express/lib/router/index.js:296:3)
   at next (<path>/node_modules/express/lib/router/index.js:190:10)
   at <path>/node_modules/express/lib/router/index.js:192:16
   at Function.match_layer (<path>/node_modules/express/lib/router/index.js:296:3)

我有app.use(express.static(__dirname + '/public')); 在我的app.js文件中。

我所有的路由都工作正常,並且登出后請求任何路由時都得到JSON響應,而公共目錄中的文件僅出現問題。

我正在使用forever start -c nodemon bin/www服務器上運行腳本

我嘗試移動app.use(express.static(__dirname + '/public')); 到頂部,但同樣的問題。

有誰知道為什么只有在登錄服務器后才能訪問公用文件夾?

我的項目文件夾的所有者和組存在問題。 我已經按照本文中的步驟進行操作(“ First Express應用程序”部分),現在一切正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM