簡體   English   中英

從/提供靜態文件

[英]Serve static file from /

如果我定義

app.use('/*', express.static(path.join(__dirname, '../pub/index.html')));

然后看來,我需要在URL中的/之后至少提供一個字符以獲取index.html。 如果使用/定義路由,則瀏覽器中的任何內容都會得到404。

如何使用/來提供默認文件?

您可以使用serve-static

app.use(serveStatic(path.join(__dirname, '../pub'), {'index' ['index.html']}));

如果您調用例如localhost:3000 ,則它應提供位於../pub中index.html

暫無
暫無

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

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