Created
July 9, 2017 02:20
-
-
Save khaosdoctor/ec761eb26883b757e7c1152ad51928ae to your computer and use it in GitHub Desktop.
Example of koa route for medium post
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 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