Skip to content

Commit

Permalink
refactor(logger-plugin): improve req type
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Apr 20, 2024
1 parent 54011eb commit 13ee1a1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/plugins/default/logger-plugin.ts
@@ -1,6 +1,20 @@
import { URL } from 'url';
import { Plugin } from '../../types';
import { getLogger } from '../../logger';
import type { IncomingMessage } from 'node:http';

type ExpressRequest = {
/** Express req.baseUrl */
baseUrl?: string;
};

type BrowserSyncRequest = {
/** BrowserSync req.originalUrl */
originalUrl?: string;
};

/** Request Types from different server libs */
type FrameworkRequest = IncomingMessage & ExpressRequest & BrowserSyncRequest;

export const loggerPlugin: Plugin = (proxyServer, options) => {
const logger = getLogger(options);
Expand All @@ -23,7 +37,7 @@ export const loggerPlugin: Plugin = (proxyServer, options) => {
* [HPM] GET /users/ -> http://jsonplaceholder.typicode.com/users/ [304]
* ```
*/
proxyServer.on('proxyRes', (proxyRes: any, req: any, res) => {
proxyServer.on('proxyRes', (proxyRes: any, req: FrameworkRequest, res) => {
// BrowserSync uses req.originalUrl
// Next.js doesn't have req.baseUrl
const originalUrl = req.originalUrl ?? `${req.baseUrl || ''}${req.url}`;
Expand Down

0 comments on commit 13ee1a1

Please sign in to comment.