Created
November 27, 2016 19:11
-
-
Save sethvincent/c087bd4a00cfd7bc777adfee44a706c3 to your computer and use it in GitHub Desktop.
a merry township
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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