Skip to content

Commit

Permalink
refactor: fix circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Jun 4, 2024
1 parent 82aaf0a commit bb48375
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- fix(logger-plugin): fix missing target port
- ci(package): npm package provenance
- fix(logger-plugin): log target port when router option is used
- refactor: fix circular dependencies

## [v3.0.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v3.0.0)

Expand Down
12 changes: 12 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { HttpProxyMiddleware } from './http-proxy-middleware';
import type { Options, RequestHandler, NextFunction } from './types';
import type * as http from 'http';

export function createProxyMiddleware<
TReq = http.IncomingMessage,
TRes = http.ServerResponse,
TNext = NextFunction,
>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext> {
const { middleware } = new HttpProxyMiddleware<TReq, TRes>(options);
return middleware as unknown as RequestHandler<TReq, TRes, TNext>;
}
13 changes: 1 addition & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import { HttpProxyMiddleware } from './http-proxy-middleware';
import type { Options, RequestHandler, NextFunction } from './types';
import type * as http from 'http';

export function createProxyMiddleware<
TReq = http.IncomingMessage,
TRes = http.ServerResponse,
TNext = NextFunction,
>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext> {
const { middleware } = new HttpProxyMiddleware<TReq, TRes>(options);
return middleware as unknown as RequestHandler<TReq, TRes, TNext>;
}
export * from './factory';

export * from './handlers';

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/create-proxy-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createProxyMiddleware } from '..';
import { createProxyMiddleware } from '../factory';
import { Debug } from '../debug';
import { Filter, RequestHandler } from '../types';
import { legacyOptionsAdapter } from './options-adapter';
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/options-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as url from 'url';
import { Filter, Options } from '..';
import { Filter, Options } from '../types';
import { LegacyOptions } from './types';
import { Debug } from '../debug';
import { getLogger } from '../logger';
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as http from 'http';
import { Options } from '..';
import { Options } from '../types';

/**
* @deprecated
Expand Down

0 comments on commit bb48375

Please sign in to comment.