Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit de0c973

Browse filesBrowse files
authored
build(prettier): improve prettier setup (#1108)
* build(prettier): improve prettier setup * chore(prettier): fix prettier lint
1 parent d5aac9e commit de0c973
Copy full SHA for de0c973
Expand file treeCollapse file tree

38 files changed

+159
-231
lines changed

‎.prettierrc

Copy file name to clipboardExpand all lines: .prettierrc
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
"printWidth": 100,
33
"tabWidth": 2,
44
"semi": true,
5-
"singleQuote": true
5+
"singleQuote": true,
6+
"plugins": ["@trivago/prettier-plugin-sort-imports"],
7+
"importOrder": ["^node:.*$", "<THIRD_PARTY_MODULES>", "^[./]"],
8+
"importOrderSeparation": true,
9+
"importOrderSortSpecifiers": true
610
}

‎.vscode/settings.json

Copy file name to clipboardExpand all lines: .vscode/settings.json
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
"editor.codeActionsOnSave": {
44
"source.fixAll.eslint": "explicit"
55
},
6+
"editor.defaultFormatter": "esbenp.prettier-vscode",
7+
"editor.formatOnSave": true,
68
"markdown.extension.toc.levels": "2..3"
79
}

‎README.md

Copy file name to clipboardExpand all lines: README.md
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ Proxy `/api` requests to `http://www.example.org`
2828

2929
```typescript
3030
// typescript
31-
3231
import * as express from 'express';
33-
import type { Request, Response, NextFunction } from 'express';
34-
32+
import type { NextFunction, Request, Response } from 'express';
3533
import { createProxyMiddleware } from 'http-proxy-middleware';
3634
import type { Filter, Options, RequestHandler } from 'http-proxy-middleware';
3735

‎cspell.json

Copy file name to clipboardExpand all lines: cspell.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"language": "en",
3-
"spellCheckDelayMs": 500,
43
"dictionaries": ["node", "npm", "typescript", "contributors"],
54
"ignorePaths": [
65
"node_modules/**",
@@ -46,6 +45,7 @@
4645
"restream",
4746
"snyk",
4847
"streamify",
48+
"trivago",
4949
"tseslint",
5050
"typicode",
5151
"vhosted",

‎eslint.config.mjs

Copy file name to clipboardExpand all lines: eslint.config.mjs
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// @ts-check
2-
32
import eslint from '@eslint/js';
4-
import tseslint from 'typescript-eslint';
5-
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
63
import globals from 'globals';
4+
import tseslint from 'typescript-eslint';
75

86
export default tseslint.config(
97
// replacement of legacy `.eslintignore`
@@ -13,7 +11,6 @@ export default tseslint.config(
1311
// extends...
1412
eslint.configs.recommended,
1513
...tseslint.configs.recommended,
16-
eslintPluginPrettierRecommended,
1714
// base config
1815
{
1916
languageOptions: {
@@ -37,7 +34,6 @@ export default tseslint.config(
3734
'error',
3835
{ vars: 'all', args: 'none', ignoreRestSiblings: false },
3936
],
40-
'prettier/prettier': 'warn',
4137
},
4238
},
4339
{

‎examples/next-app/pages/api/_proxy.ts

Copy file name to clipboardExpand all lines: examples/next-app/pages/api/_proxy.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NextApiRequest, NextApiResponse } from 'next';
2+
23
import { createProxyMiddleware } from '../../../../dist';
34

45
// Singleton

‎examples/next-app/pages/api/users.ts

Copy file name to clipboardExpand all lines: examples/next-app/pages/api/users.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NextApiRequest, NextApiResponse, PageConfig } from 'next';
2+
23
import { proxyMiddleware } from './_proxy';
34

45
// https://nextjs.org/docs/pages/building-your-application/routing/api-routes

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"@commitlint/cli": "19.8.0",
6060
"@commitlint/config-conventional": "19.8.0",
6161
"@eslint/js": "9.23.0",
62+
"@trivago/prettier-plugin-sort-imports": "5.2.2",
6263
"@types/debug": "4.1.12",
6364
"@types/eslint": "9.6.1",
6465
"@types/express": "4.17.21",
@@ -70,8 +71,6 @@
7071
"@types/ws": "8.18.0",
7172
"body-parser": "1.20.3",
7273
"eslint": "9.23.0",
73-
"eslint-config-prettier": "10.1.1",
74-
"eslint-plugin-prettier": "5.2.3",
7574
"express": "4.21.2",
7675
"get-port": "5.1.1",
7776
"globals": "16.0.0",

‎recipes/servers.md

Copy file name to clipboardExpand all lines: recipes/servers.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ export const proxyMiddleware = createProxyMiddleware<NextApiRequest, NextApiResp
105105

106106
```typescript
107107
// Next project: `/pages/api/users.ts`
108-
109108
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
110109
import type { NextApiRequest, NextApiResponse } from 'next';
110+
111111
import { proxyMiddleware } from './users.proxy';
112112

113113
export default function handler(req: NextApiRequest, res: NextApiResponse) {

‎src/factory.ts

Copy file name to clipboardExpand all lines: src/factory.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { HttpProxyMiddleware } from './http-proxy-middleware';
2-
import type { Options, RequestHandler, NextFunction } from './types';
31
import type * as http from 'http';
42

3+
import { HttpProxyMiddleware } from './http-proxy-middleware';
4+
import type { NextFunction, Options, RequestHandler } from './types';
5+
56
export function createProxyMiddleware<
67
TReq = http.IncomingMessage,
78
TRes = http.ServerResponse,

‎src/get-plugins.ts

Copy file name to clipboardExpand all lines: src/get-plugins.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { Options, Plugin } from './types';
21
import {
32
debugProxyErrorsPlugin,
4-
loggerPlugin,
53
errorResponsePlugin,
4+
loggerPlugin,
65
proxyEventsPlugin,
76
} from './plugins/default';
7+
import type { Options, Plugin } from './types';
88

99
export function getPlugins<TReq, TRes>(options: Options<TReq, TRes>): Plugin<TReq, TRes>[] {
1010
// don't load default errorResponsePlugin if user has specified their own

‎src/handlers/response-interceptor.ts

Copy file name to clipboardExpand all lines: src/handlers/response-interceptor.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type * as http from 'http';
22
import * as zlib from 'zlib';
3+
34
import { Debug } from '../debug';
45
import { getFunctionName } from '../utils/function';
56

‎src/http-proxy-middleware.ts

Copy file name to clipboardExpand all lines: src/http-proxy-middleware.ts
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import type * as net from 'net';
21
import type * as http from 'http';
3-
import type * as https from 'https';
4-
import type { RequestHandler, Options, Filter, Logger } from './types';
52
import * as httpProxy from 'http-proxy';
3+
import type * as https from 'https';
4+
import type * as net from 'net';
5+
66
import { verifyConfig } from './configuration';
7+
import { Debug as debug } from './debug';
78
import { getPlugins } from './get-plugins';
9+
import { getLogger } from './logger';
810
import { matchPathFilter } from './path-filter';
911
import * as PathRewriter from './path-rewriter';
1012
import * as Router from './router';
11-
import { Debug as debug } from './debug';
13+
import type { Filter, Logger, Options, RequestHandler } from './types';
1214
import { getFunctionName } from './utils/function';
13-
import { getLogger } from './logger';
1415

1516
export class HttpProxyMiddleware<TReq, TRes> {
1617
private wsInternalSubscribed = false;

‎src/legacy/create-proxy-middleware.ts

Copy file name to clipboardExpand all lines: src/legacy/create-proxy-middleware.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { createProxyMiddleware } from '../factory';
1+
import type * as http from 'http';
2+
23
import { Debug } from '../debug';
4+
import { createProxyMiddleware } from '../factory';
35
import { Filter, RequestHandler } from '../types';
46
import { legacyOptionsAdapter } from './options-adapter';
57
import { LegacyOptions } from './types';
6-
import type * as http from 'http';
78

89
const debug = Debug.extend('legacy-create-proxy-middleware');
910

‎src/legacy/options-adapter.ts

Copy file name to clipboardExpand all lines: src/legacy/options-adapter.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as url from 'url';
2-
import { Filter, Options } from '../types';
3-
import { LegacyOptions } from './types';
2+
43
import { Debug } from '../debug';
54
import { getLogger } from '../logger';
5+
import { Filter, Options } from '../types';
66
import { Logger } from '../types';
7+
import { LegacyOptions } from './types';
78

89
const debug = Debug.extend('legacy-options-adapter');
910

‎src/legacy/types.ts

Copy file name to clipboardExpand all lines: src/legacy/types.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type * as http from 'http';
2+
23
import { Options } from '../types';
34

45
/**

‎src/path-filter.ts

Copy file name to clipboardExpand all lines: src/path-filter.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type { Filter } from './types';
1+
import type * as http from 'http';
22
import * as isGlob from 'is-glob';
33
import * as micromatch from 'micromatch';
44
import * as url from 'url';
5+
56
import { ERRORS } from './errors';
6-
import type * as http from 'http';
7+
import type { Filter } from './types';
78

89
export function matchPathFilter<TReq = http.IncomingMessage>(
910
pathFilter: Filter<TReq> = '/',

‎src/path-rewriter.ts

Copy file name to clipboardExpand all lines: src/path-rewriter.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { isPlainObject } from 'is-plain-object';
2-
import { ERRORS } from './errors';
2+
33
import { Debug } from './debug';
4+
import { ERRORS } from './errors';
45

56
const debug = Debug.extend('path-rewriter');
67

‎src/plugins/default/error-response-plugin.ts

Copy file name to clipboardExpand all lines: src/plugins/default/error-response-plugin.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type * as http from 'http';
22
import type { Socket } from 'net';
3+
34
import { getStatusCode } from '../../status-code';
45
import { Plugin } from '../../types';
56

‎src/plugins/default/logger-plugin.ts

Copy file name to clipboardExpand all lines: src/plugins/default/logger-plugin.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { IncomingMessage } from 'node:http';
2+
13
import { URL } from 'url';
2-
import { Plugin } from '../../types';
4+
35
import { getLogger } from '../../logger';
4-
import type { IncomingMessage } from 'node:http';
6+
import { Plugin } from '../../types';
57
import { getPort } from '../../utils/logger-plugin';
68

79
type ExpressRequest = {

‎src/router.ts

Copy file name to clipboardExpand all lines: src/router.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isPlainObject } from 'is-plain-object';
2+
23
import { Debug } from './debug';
34

45
const debug = Debug.extend('router');

‎src/types.ts

Copy file name to clipboardExpand all lines: src/types.ts
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Based on definition by DefinitelyTyped:
33
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
44
*/
5-
65
import type * as http from 'http';
76
import type * as httpProxy from 'http-proxy';
87
import type * as net from 'net';

‎test/e2e/express-error-middleware.spec.ts

Copy file name to clipboardExpand all lines: test/e2e/express-error-middleware.spec.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { createApp, createProxyMiddleware } from './test-kit';
21
import * as request from 'supertest';
32

3+
import { createApp, createProxyMiddleware } from './test-kit';
4+
45
describe('express error middleware', () => {
56
it('should propagate error to express', async () => {
67
let httpProxyError: Error | undefined;

‎test/e2e/express-router.spec.ts

Copy file name to clipboardExpand all lines: test/e2e/express-router.spec.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as express from 'express';
22
import * as request from 'supertest';
3-
import { createProxyMiddleware } from './test-kit';
3+
44
import { Options } from '../../src/index';
5+
import { createProxyMiddleware } from './test-kit';
56

67
describe('Usage in Express', () => {
78
let app: express.Express;

‎test/e2e/http-proxy-middleware.spec.ts

Copy file name to clipboardExpand all lines: test/e2e/http-proxy-middleware.spec.ts
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { createProxyMiddleware, createApp, createAppWithPath, fixRequestBody } from './test-kit';
2-
import * as request from 'supertest';
3-
import { Mockttp, getLocal, CompletedRequest } from 'mockttp';
4-
import type * as http from 'http';
5-
import type * as express from 'express';
61
import * as bodyParser from 'body-parser';
2+
import type * as express from 'express';
3+
import type * as http from 'http';
4+
import { CompletedRequest, Mockttp, getLocal } from 'mockttp';
5+
import * as request from 'supertest';
6+
77
import type { Logger } from '../../src/types';
8+
import { createApp, createAppWithPath, createProxyMiddleware, fixRequestBody } from './test-kit';
89

910
describe('E2E http-proxy-middleware', () => {
1011
describe('http-proxy-middleware creation', () => {

‎test/e2e/http-server.spec.ts

Copy file name to clipboardExpand all lines: test/e2e/http-server.spec.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as http from 'http';
2-
import { createProxyMiddleware } from './test-kit';
32
import * as request from 'supertest';
43

4+
import { createProxyMiddleware } from './test-kit';
5+
56
describe('http integration', () => {
67
it('should work with raw node http RequestHandler', async () => {
78
const handler = createProxyMiddleware({

‎test/e2e/path-rewriter.spec.ts

Copy file name to clipboardExpand all lines: test/e2e/path-rewriter.spec.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { createProxyMiddleware, createApp } from './test-kit';
1+
import { Mockttp, getLocal } from 'mockttp';
22
import * as request from 'supertest';
3-
import { getLocal, Mockttp } from 'mockttp';
3+
4+
import { createApp, createProxyMiddleware } from './test-kit';
45

56
describe('E2E pathRewrite', () => {
67
let mockTargetServer: Mockttp;

‎test/e2e/plugins.spec.ts

Copy file name to clipboardExpand all lines: test/e2e/plugins.spec.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { createProxyMiddleware, createApp } from './test-kit';
1+
import { Mockttp, getLocal } from 'mockttp';
22
import * as request from 'supertest';
3-
import { getLocal, Mockttp } from 'mockttp';
3+
44
import type { Options, Plugin } from '../../src/types';
5+
import { createApp, createProxyMiddleware } from './test-kit';
56

67
describe('E2E Plugins', () => {
78
let mockTargetServer: Mockttp;

‎test/e2e/response-interceptor.spec.ts

Copy file name to clipboardExpand all lines: test/e2e/response-interceptor.spec.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import * as request from 'supertest';
2+
13
import { createProxyMiddleware, responseInterceptor } from '../../src';
24
import { createApp } from './test-kit';
3-
import * as request from 'supertest';
45

56
describe('responseInterceptor()', () => {
67
let agent: request.Agent;

‎test/e2e/router.spec.ts

Copy file name to clipboardExpand all lines: test/e2e/router.spec.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { createProxyMiddleware, createApp, createAppWithPath } from './test-kit';
21
import { ErrorRequestHandler } from 'express';
3-
import * as request from 'supertest';
4-
import { getLocal, generateCACertificate, Mockttp } from 'mockttp';
52
import * as getPort from 'get-port';
3+
import { Mockttp, generateCACertificate, getLocal } from 'mockttp';
4+
import * as request from 'supertest';
5+
6+
import { createApp, createAppWithPath, createProxyMiddleware } from './test-kit';
67

78
const untrustedCACert = generateCACertificate({ bits: 1024 });
89

‎test/e2e/websocket.spec.ts

Copy file name to clipboardExpand all lines: test/e2e/websocket.spec.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import * as getPort from 'get-port';
12
import * as http from 'http';
23
import * as WebSocket from 'ws';
34
import { Server as WebSocketServer } from 'ws';
4-
import * as getPort from 'get-port';
5-
import { createProxyMiddleware, createApp } from './test-kit';
5+
66
import type { RequestHandler } from '../../src/types';
7+
import { createApp, createProxyMiddleware } from './test-kit';
78

89
/********************************************************************
910
* - Not possible to use `supertest` to test WebSockets

‎test/legacy/http-proxy-middleware.spec.ts

Copy file name to clipboardExpand all lines: test/legacy/http-proxy-middleware.spec.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { createApp, createAppWithPath } from '../e2e/test-kit';
2-
import { legacyCreateProxyMiddleware, LegacyOptions } from '../../src';
3-
import * as request from 'supertest';
41
import { Mockttp, getLocal } from 'mockttp';
2+
import * as request from 'supertest';
3+
4+
import { LegacyOptions, legacyCreateProxyMiddleware } from '../../src';
5+
import { createApp, createAppWithPath } from '../e2e/test-kit';
56

67
describe('legacyCreateProxyMiddleware()', () => {
78
const mockServer: Mockttp = getLocal();

‎test/types.spec.ts

Copy file name to clipboardExpand all lines: test/types.spec.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable @typescript-eslint/no-unused-expressions */
2-
32
import * as express from 'express';
43
import * as http from 'http';
5-
import { createProxyMiddleware as middleware, fixRequestBody, responseInterceptor } from '../src';
4+
5+
import { fixRequestBody, createProxyMiddleware as middleware, responseInterceptor } from '../src';
66
import type { Options, RequestHandler } from '../src/types';
77

88
describe('http-proxy-middleware TypeScript Types', () => {

‎test/unit/fix-request-body.spec.ts

Copy file name to clipboardExpand all lines: test/unit/fix-request-body.spec.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Socket } from 'net';
21
import { ClientRequest, IncomingMessage, ServerResponse } from 'http';
2+
import { Socket } from 'net';
33
import * as querystring from 'querystring';
4-
import { fixRequestBody, BodyParserLikeRequest } from '../../src/handlers/fix-request-body';
4+
5+
import { BodyParserLikeRequest, fixRequestBody } from '../../src/handlers/fix-request-body';
56

67
const fakeProxyRequest = (): ClientRequest => {
78
const proxyRequest = new ClientRequest('http://some-host');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.