Spaces:
Sleeping
Sleeping
Add logging
Browse files- src/server/server.ts +6 -0
src/server/server.ts
CHANGED
|
@@ -15,8 +15,14 @@ export class Server {
|
|
| 15 |
this.app.use(express.json());
|
| 16 |
this.app.use(express.urlencoded({ extended: true }));
|
| 17 |
this.app.use((req, res, next) => {
|
|
|
|
| 18 |
this.logger.info(`[${new Date().toISOString()}] ${req.method} ${req.originalUrl}`);
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
next();
|
| 21 |
})
|
| 22 |
}
|
|
|
|
| 15 |
this.app.use(express.json());
|
| 16 |
this.app.use(express.urlencoded({ extended: true }));
|
| 17 |
this.app.use((req, res, next) => {
|
| 18 |
+
const start = Date.now();
|
| 19 |
this.logger.info(`[${new Date().toISOString()}] ${req.method} ${req.originalUrl}`);
|
| 20 |
|
| 21 |
+
res.on('finish', () => {
|
| 22 |
+
const duration = Date.now() - start;
|
| 23 |
+
this.logger.info(`${req.method} ${req.originalUrl} ${res.statusCode} - ${duration}ms`);
|
| 24 |
+
});
|
| 25 |
+
|
| 26 |
next();
|
| 27 |
})
|
| 28 |
}
|