Skip to content

Commit

Permalink
fix(logger-plugin): improve log output
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Apr 16, 2022
1 parent af9901f commit e3326c7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/plugins/default/logger-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@ export const loggerPlugin: Plugin = (proxyServer, options) => {
* ```
*/
proxyServer.on('proxyRes', (proxyRes: any, req: any, res) => {
const exchange = `[HPM] ${req.method} ${req.baseUrl}${req.path} -> ${proxyRes.req.protocol}//${proxyRes.req.host}${proxyRes.req.path} [${proxyRes.statusCode}]`;
// BrowserSync uses req.originalUrl
const originalUrl = req.originalUrl ?? `${req.baseUrl}${req.path}`;
const exchange = `[HPM] ${req.method} ${originalUrl} -> ${proxyRes.req.protocol}//${proxyRes.req.host}${proxyRes.req.path} [${proxyRes.statusCode}]`;
logger.info(exchange);
});

/**
* When client opens WebSocket connection
*/
proxyServer.on('open', (socket) => {
logger.info('[HPM] Client connected: %o', socket.address());
});

/**
* When client closes WebSocket connection
*/
proxyServer.on('close', (req, proxySocket, proxyHead) => {
logger.info('[HPM] Client disconnected');
logger.info('[HPM] Client disconnected: %o', proxySocket.address());
});
};

0 comments on commit e3326c7

Please sign in to comment.