我对Backbone.history.start({pushState: true});
何时激活有疑问
我使用骨干路由器'example/:id':'test'
,浏览器返回错误
GET myhost:1337/example/js/views/test.js 404(未找到)
例如,我想使用 Backbone 进行旋转,myhost:1337/example/test
而无需请求 nodejs。
si,我不知道为什么,
可能是我的服务器 Nodejs?或者可能是我的代码写得不好?提前致谢
我的服务器代码是
//var http = require('http');
var path = require('path'),
express = require('express'),
routes = require('./routes/index'),
http = require('http'),
app = require('express')();
app.configure(function(){
//app.set('view options',{layout: false });
app.set('port', process.env.PORT || 1337);
app.use(express.bodyParser()),
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router); // you need this line so the .get etc. routes are run and if an error within, then the error is parsed to the ned middleware (your error reporter)
app.use(function(err, req, res, next) {
if(!err) return next(); // you also need this line
console.log("error!!!");
res.send("error!!!");
});
});
app.get('*',function(req,res){
res.setHeader('content-type', 'text/javascript');
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.redirect('http://localhost:1337#'+req.url);
});
http.createServer(app).listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
});