Skip to content

Instantly share code, notes, and snippets.

@fizerkhan

fizerkhan/app.js

Created Jan 20, 2018
Embed
What would you like to do?
Sample App for Koa middleware with Atatus
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