Created
January 20, 2018 13:08
Sample App for Koa middleware with Atatus
This file contains hidden or 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 atatus = require("atatus-node"); | |
atatus.start({ | |
apiKey: 'API KEY', | |
}); | |
const koaAtatus = require('koa-atatus')(atatus); | |
const Koa = require('koa'), | |
Router = require('koa-router'); | |
const app = new Koa(); | |
const router = new Router(); | |
router.use(koaAtatus); // This line should be added for every router instance. | |
// Routes | |
router.get('/test', async (ctx) => { | |
ctx.body = { name: 'John', age: 56 }; | |
}); | |
router.get('/estatus', async (ctx) => { | |
ctx.status = 405 | |
ctx.body = [{ name: 'Foo'}, { name: 'Bar' }]; | |
}); | |
router.get('/try', async function (next) { | |
ctx2.body = 'TrySomethingWeird'; | |
}); | |
// For error capturing | |
app.on('error', (err, ctx) => { | |
atatus.notifyError(err); | |
}); | |
app.use(router.routes()); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment