【发布时间】:2013-11-29 03:55:08
【问题描述】:
我对 Web 开发比较陌生。我正在使用节点(带快递)和角度 JS。虽然解决方案可能很简单,但我无法确定为什么每个请求的文件 (css/javascript/html) 的内容都与我的 index.html 文件的内容一起返回。
以下来自 chrome 检查器的屏幕截图说明了该问题:
controller.js 文件的内容显示的实际上是 index.html 文件的内容。
您可以从屏幕截图中的索引文件中看到相关内容。以下是节点服务器代码:
/**
* Module dependencies.
*/
var express = require('express'),
routes = require('./routes'),
api = require('./routes/api');
var app = module.exports = express();
// Configuration
app.configure(function() {
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/public'));
app.use(app.router);
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
app.get('/partials/:name', routes.partials);
// JSON API
app.get('/api/name', api.name);
// redirect all others to the index (HTML5 history)
app.get('*', routes.index);
// Start server
app.listen(3000, function(){
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});
routes.js 文件(在 routes 目录中):
/*
* GET home page.
*/
//get correct directory path
var filePath = __dirname.replace('routes', 'views/')
exports.index = function(req, res) {
res.sendfile(filePath + 'index.html');
};
exports.partials = function (req, res) {
var name = req.params.name;
res.sendfile(filePath + 'partials/' + name + '.html');
};
似乎每个资源请求都返回索引的内容(包括图像文件)。任何想法或建议将不胜感激。
【问题讨论】:
标签: javascript html css node.js angularjs