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 66e3217
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
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 66e3217

Please sign in to comment.