我试图使用express制作虚拟静态路径,但是有些问题我无法处理。 这就是我在Express的文档中找到的内容:
// Serve static content for the app from the “public” directory
// in the application directory:
// GET /style.css etc
app.use(express.static(__dirname + '/public'));
// Mount the middleware at “/static” to serve static content only when
// their request path is prefixed with “/static”:
// GET /static/style.css etc.
app.use('/static', express.static(__dirname + '/public'));
以下是目录结构:
disk
static
css
js
img
index.html
server.js
如果我只是尝试下面的代码,没有任何问题。我可以在Chrome DevTools中的Sources选项中找到相同的目录结构;
app.use(express.static(__dirname + '/dist'));
但是当我尝试使用下面的代码创建虚拟目录时,它出错了。
app.use('/music', express.static(__dirname + '/dist'));
我的网站无法正常显示,控制台显示获取静态文件的错误。这是我在Chrome DevTools中找到的内容: errors, directory structures
我认为目录结构应该是这样的" music / static / css"。 谁能告诉我什么是错的。 THX!