Skip to content

Instantly share code, notes, and snippets.

@sethvincent
Created November 27, 2016 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethvincent/c087bd4a00cfd7bc777adfee44a706c3 to your computer and use it in GitHub Desktop.
Save sethvincent/c087bd4a00cfd7bc777adfee44a706c3 to your computer and use it in GitHub Desktop.
a merry township
const merry = require('merry')
const township = require('township')
const ship = township()
const log = merry.log('main')
const app = merry({
log: { stream: process.stdout },
env: { PORT: 8080 }
})
// handle uncaught exceptions / uncaught rejections
app.catch((error) => log.error(error))
// or maybs we should do:
app.on('error', (error) => log.error(error))
app.router({ default: '/404' }, [
[ '/', (req, res, ctx, done) => {
done(null, 'hello world')
}],
[ '/error', (req, res, ctx, done) => {
done(merry.error(500, 'server error!'))
}],
['/login', (req, res, ctx, done) => {
township.login(req, res, ctx, function (err, statusCode, body) {
done(null, body)
}
}],
['/register', (req, res, ctx, done) => {
township.register(req, res, ctx, function (err, statusCode, body) {
done(null, body)
}
}],
[ '/404', merry.notFound() ]
])
merry.listen(env.PORT, app.start())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment