【发布时间】:2015-12-29 05:50:51
【问题描述】:
假设我通过express 服务器在根目录中提供以下index.html 文件。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<h1>Hello</h1>
<script src="/public/system.js"></script>
<script src="/public/config.js"></script>
<script>System.import("app/main")</script>
</body>
</html>
system.js 和 config.js 都在公共目录文件夹中。
要让index.html 加载这些文件,我必须在我的app.js 文件中包含以下行,以便可以在公共文件夹中搜索请求:
app.use(express.static(path.join(config.root, 'public')));
为什么会这样?为什么index.html 不能正确引用没有上述行的文件,因为资源的src 路径是正确的? app/main 也是如此。 index.html 使用的每个资源是否真的必须通过app.use() 静态提供?
【问题讨论】: