I've got problemas with Backbone.history.start({pushState: true}); when is actived
I use the backbone router 'example/:id':'test' and the browser returns me an error
GET myhost:1337/example/js/views/test.js 404 (Not Found)
I want to rotate with Backbone for example myhost:1337/example/test without the necessity to request nodejs.
si, I dunno why,
Could be my server Nodejs? Or Could be my code that it's not well written? Thanks in advance
MY server code is
//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'));
});
This is something with your server. I'm willing to bet you didn't hold the shift key down when you typed out your route, so you have something like this in your server
app.get('example?:id':'test', function() {});
When you should have:
app.get('example/:id':'test', function() {});
This block:
app.post('/addPlace?:?',routes.addPlace);
app.get('/searchPlace?:q',routes.searchPlace);
app.post('/showPlace',routes.showPlace);
app.get('/showPlaceById?:id',routes.showPlaceById)
app.post('/deletePlace?:?',routes.deletePlace);
See the ?'s everywhere? This should really be:
app.post('/addPlace',routes.addPlace);
app.get('/searchPlace/:q',routes.searchPlace);
app.post('/showPlace',routes.showPlace);
app.get('/showPlaceById/:id',routes.showPlaceById)
app.post('/deletePlace',routes.deletePlace);
If you change that, /showPlaceById/:id will return what you expect.