I'm probably tackling this the wrong way but bear with me:
in my server.js I got this
tweetThisThing = require('./lib/kustomtwitter'),
app.get('/tweet/:msg', function(req, res){
var tweet = req.params.msg;
tweetThisThing(tweet); // le magic
res.redirect('/cars');
});
When I direct my browser to http://localhost:3000/tweet/This will be tweeted a tweet is successfully being sent out.
When I try to invoke the same express endpoint through Backbone like so:
In my Backbone script I got this
app.navigate('tweet/' + theMessageThatWillBeTweeted, {trigger:true, replace: true});
, Backbone always forces a hash in the route and then fails to send the tweet http://localhost:3000/#tweet/This will not be tweeted
I know this is expected behaviour and some "workarounds" involve adding pushState:true to my Backbone script, but I don't seem to be able to get it working.
Is there an easy way to get the behaviour I want or do I need to setup a backbone route for this specific usecase?
If turning on pushState with
Backbone.history.start({pushState: true});
doesn't work an alternative is to bypass Backbone all together and just use jQuery.get. For example:
$.get('tweet/' + theMessageThatWillBeTweeted, function(result) {
// Also instead of redirecting you could output the twitter response code
// and verify the request was a success here
console.log(result);
});
By the way, using GET probably isn't the best way to do this. You'd probably be better off using POST which would give you much more flexibility and cleaner urls.