Skip to content

Instantly share code, notes, and snippets.

@khaosdoctor
Created July 9, 2017 02:20
Show Gist options
  • Save khaosdoctor/ec761eb26883b757e7c1152ad51928ae to your computer and use it in GitHub Desktop.
Save khaosdoctor/ec761eb26883b757e7c1152ad51928ae to your computer and use it in GitHub Desktop.
Example of koa route for medium post
const route = require('koa-route')
const logger = require('knoblr')
const mongoose = require('mongoose')
/**
* Rota de obtenção de status da API
*
* @param {Object} ctx Contexto do Koa (Preenchido automaticamente)
* @param {Object} next Próximo middleware do Koa (Preenchido automaticamente)
* @param {Mongoose} driver Model do Mongoose
* @memberof getStatus
* @return void
* @private
* @func getStatus
*/
function getStatus (ctx, next, driver = mongoose) {
logger.info(`Solicitação de status da API recebida`)
if (driver.connection.readyState === 1) {
ctx.status = 200
ctx.body = 'Up and Running'
} else {
ctx.body = 'Server unavailable'
ctx.status = 503
}
}
// Exporta a rota e também a função interna (para poder importar nos testes)
module.exports = {
route: route.get('/status', getStatus),
func: getStatus
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment