我在提供位于公共檔案夾內子目錄中的 html 檔案時遇到問題。我的目錄結構如下:
public/
HTML/
index.html
index.js
我想為根路由提供 index.html。
這不起作用:
app.use('/',express.static(path.join(__dirname,'public')));
uj5u.com熱心網友回復:
根據檔案,這應該足夠了:
app.use(express.static('public'))
它也給你這樣的例子
http://localhost:3000/images/kitten.jpg
http://localhost:3000/css/style.css
http://localhost:3000/js/app.js
http://localhost:3000/images/bg.png
http://localhost:3000/hello.html
除了解釋如何設定多個公共目錄之外,它并沒有更進一步。無論如何,它在我的專案中對我有用。
也許您需要直接說明app.use(express.static('html'))或app.use(express.static('public/html')). 讓我知道什么對你有用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/398915.html
