-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): koa not handling wait in middleware
- Loading branch information
Bartholomé
committed
Aug 9, 2022
1 parent
e05d241
commit 583b6ea
Showing
1 changed file
with
17 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
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() | ||
} |