節點JS一直給我的文件未找到錯誤讀取使用JavasScript文件..的NodeJS不能在HTML
我的目錄結構:
app
--main
--app.js
--bootstrap.js
--route.js
bower_components
--requirejs
--require.js
app.js
index.html
我相信這個代碼應該把所有的靜態文件目錄到中間件棧。
app.use(express.static(path.join(__dirname, '/app')))
app.use(express.static(path.join(__dirname, '/bower_components')))
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
這是我的HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div style="color:red"> hello I am in index11</div>
<div ng-view></div>
<script type="text/javascript" src="app/test.js"></script>
<script type="text/javascript" data-main="app/app.js" src="bower_components/requirejs/require.js"></script>
</body>
</html>
我得到的字符串中的HTML。但是,我看到這個錯誤 Chrome開發者工具
遠程地址:[:: 1]:3000 請求URL:http://localhost:3000/bower_components/requirejs/require.js 請求方法:GET 狀態代碼:404未找到
是的,我沒有和我刪除了公衆和查看目錄使用角路徑 –
那麼表示應該如何提供內容?你的路線不公開。 –