Skip to content

Commit

Permalink
fix(api): koa not handling wait in middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartholomé committed Aug 9, 2022
1 parent e05d241 commit 583b6ea
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/api/middlewares/log.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { container } from "tsyringe"
import chalk from "chalk"
import { Context, Next } from "koa"

import { Logger } from "@services"
import { waitForDependency } from "@utils/functions"

export function globalLog(ctx: Context, next: Next) {
waitForDependency(Logger).then(logger => {
// don't log anything if the request has a `logIgnore` query params
if (!ctx.query.logIgnore) {
const { method, url } = ctx.request
const logger = container.resolve(Logger)

const message = `(API) ${method} - ${url}`
const chalkedMessage = `(${chalk.bold.white('API')}) ${chalk.bold.green(method)} - ${chalk.bold.blue(url)}`
export async function globalLog(ctx: Context, next: Next) {

logger.console('info', chalkedMessage)
logger.file('info', message)

} else {
delete ctx.query.logIgnore
}
// don't log anything if the request has a `logIgnore` query params
if (!ctx.query.logIgnore) {
const { method, url } = ctx.request

return next()
});
const message = `(API) ${method} - ${url}`
const chalkedMessage = `(${chalk.bold.white('API')}) ${chalk.bold.green(method)} - ${chalk.bold.blue(url)}`

logger.console('info', chalkedMessage)
logger.file('info', message)

} else {
delete ctx.query.logIgnore
}

return next()
}

0 comments on commit 583b6ea

Please # to comment.