I'm new to node and flatiron.
I'm trying to use flatiron to create an app that uses Instagram's realtime api. So the first step is to handle the subscription, and I'm stumbling on sending back the hub.challenge response.
I tried looking at the examples in GitHub, the closes that I can get is the app.res.json function.
Here's my starting app...
var flatiron = require('flatiron'),
qs = require('qs');
// declarations
var instagramClientId = 'ID',
instagramClientSecret = 'SECRET',
app.use(flatiron.plugins.http);
app.router.configure({ 'strict':false });
//----- routes --------------------------------------------------
// index
app.router.get('/', function () {
this.res.writeHead(200, {'content-type':'text/plain'});
this.res.end('index');
});
// callback
app.router.path('/callback', function () {
// GET /callback
// If param hub.challenge is present, renders its value
// This URL is used by subscription system of Instagram
// to check if the callback URL provided when creating the subscription
// is valid and works fine
this.get(function () {
if (this.req.query['hub.challenge'] != null) {
//this.res.send(this.req.query['hub.challenge']);
console.log(this.res)
}
else {
}
});
// post
// @todo
this.res.writeHead(200, { 'content-type':'text/plain' });
this.res.end('hello!');
});
});
// start the server
app.start(8080, function (err) {
if (err) {
throw err;
}
var addr = app.server.address();
app.log.info('listening on http://' + addr.address + ':' + addr.port); });