将node express配置为提供静态的bower_components文件夹?

19 浏览
0 Comments

将node express配置为提供静态的bower_components文件夹?

我有一个目录结构

projectName
    | - bower_components/
    | - public/
        | - css
        | - js
        | - index.html
    | - Gruntfile.js
    | - package.json
    | - bower.json
    | - app.js

我想要使用node启动我的应用并且用node提供index.html。所以在app.js中我有:

var express = require('express');
var port = process.env.PORT || 3000;
var app = express();
app.configure(function(){
    // 从public目录提供内容
    app.use(express.static(__dirname + '/public'));
    app.use(app.router);
    app.use(express.logger()); 
});
app.listen(port, function(){
    console.log('Express服务器正在监听端口 ' + port);
});

index.html的底部我有:






当我启动服务器时,index.html显示出来,但以上的库都没有加载。我收到了错误(404):

GET http://localhost:3000/bower_components/jquery/jquery.js 404 (Not Found) localhost/:32
GET http://localhost:3000/bower_components/d3/d3.js 404 (Not Found) localhost/:33
GET http://localhost:3000/bower_components/bootstrap/dist/js/bootstrap.js 404 (Not Found) localhost/:34
GET http://localhost:3000/bower_components/spin.js/spin.js 404 (Not Found) localhost/:35
GET http://localhost:3000/bower_components/mustache/mustache.js 404 (Not Found) 

如何提供bower_components中的文件?

0