Motley

motley

Get Started in 3 shell commands:

git clone git@github.com:carlos8f/motley-init.git
cd motley-init && npm install
node server.js

(or just fork the motley-init repo!)

Example server.js

var motley = require('motley')

try {
  var app = motley({
    _ns: 'motley',
    _maps: [
      // require()'ed motley plugins go here.
    ],
    'hooks.listen[]': function container (get, set) {
      return function task (cb) {
        get('console').log('listening on http://localhost:' + get('site.server').address().port + '/')
        setImmediate(cb)
      }
    },
    'middleware[]': function container (get, set) {
      return function handler (req, res, next) {
        res.vars || (res.vars = {})
        res.vars.nonce = Math.random()
        next()
      }
    },
    'controllers[]': function container (get, set) {
      return get('controller')()
        .get('/', function (req, res, next) {
          res.json({
            'welcome': 'to ' + get('conf.site.title') + '!',
            'version': require('./package.json').version,
            'nonce': res.vars.nonce
          })
        })
    },
    'hooks.close[]': function container (get, set) {
      return function task (cb) {
        get('console').log('\n\nmotley says goodbye :)\n')
        setImmediate(cb)
      }
    }
  })
}
catch (err) {
  exit(err)
}

function exit (err) {
  console.error(err)
  console.error(err.stack)
  process.exit(1)
}

app.listen(function (err) {
  if (err) exit(err)
  function onExit () {
    app.close(function (err) {
      if (err) exit(err)
    })
  }
  process.once('SIGINT', onExit)
  process.once('SIGTERM', onExit)
})

License

Motley is released under the MIT license.