Skip to content

Instantly share code, notes, and snippets.

@Marak
Created August 2, 2012 21:50
Show Gist options
  • Save Marak/3240974 to your computer and use it in GitHub Desktop.
Save Marak/3240974 to your computer and use it in GitHub Desktop.
WIP - Flatironisms

WIP

log all incoming http requests

app.http.before.push(function(req, res){
  app.log.info(req.url);
  res.emit('next');
})

access form and query string data

app.router.post('/foo/bar', function () {
  var submitted = this.req.body,
      query     = this.req.query;
  res.end('posted');
});
curl -v -X POST --data 'foo="bar"&bar="baz"' 'localhost:8080/foo/bar?a="1"&b="2"`

create simple command line interface (CLI)

var flatiron = require('flatiron'),
    app = flatiron.app;

app.use(flatiron.plugins.cli, {
  dir: __dirname,
  usage: [
    'This is a basic flatiron cli application example!',
    '',
    'hello - say hello to somebody.'
  ]
});

app.cmd('hello', function () {
  app.prompt.get('name', function (err, result) {
    app.log.info('hello '+result.name+'!');
  })
})

app.start();

using a config.json file

app.config.use('file', { file: './config/foo.json' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment