Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tailing new line on http-log events #50

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/50.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove tailing new line on http-log events
8 changes: 6 additions & 2 deletions src/app-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,12 @@ export class AppService extends EventEmitter {
}

private onMorganLog(str: string) {
const redactedStr = str.replace(/access_token=.*?(&|\s|$)/, "access_token=<REDACTED>$1");
this.emit("http-log", redactedStr);
// The dependency `morgan` expects to write to a stream and adds a new line at the end.
// Listeners of the `http-log` event expect there not to be a new line, so the string
// can be handed to a logger like `console.log()` without displaying empty lines.
str = str.replace(/\n$/, "");
str = str.replace(/access_token=.*?(&|\s|$)/, "access_token=<REDACTED>$1");
this.emit("http-log", str);
}

private isInvalidToken(req: Request, res: Response): boolean {
Expand Down