Skip to content

Commit 57d9683

Browse files
committed
feat: enable logging hook for external requests
1 parent 343a975 commit 57d9683

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

hooks/logging.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { HookContext } from '@feathersjs/feathers';
2+
3+
export default async (context: HookContext): Promise<HookContext> => {
4+
if (context.params.provider) {
5+
const { method, path, id, params: { user: { username }} } = context;
6+
const timestamp = new Date().toLocaleString('default', { timeStyle: 'medium', dateStyle: 'short' });
7+
const message = `${method.toUpperCase()}: /${path}/${id || ''}`;
8+
9+
console.log(`[${timestamp}] ${message} ${username || ''}`);
10+
}
11+
return context;
12+
};
13+

services/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Votes from './votes/votes.service';
66
import Auth from './auth/auth.service';
77

88
import tryAuthenticate from '../hooks/tryAuthenticate';
9+
import logging from '../hooks/logging';
910

1011
export default (app: Application): void => {
1112
app.configure(Auth);
@@ -17,6 +18,9 @@ export default (app: Application): void => {
1718
app.hooks({
1819
before: {
1920
all: tryAuthenticate
21+
},
22+
after: {
23+
all: logging
2024
}
2125
});
2226
};

0 commit comments

Comments
 (0)