Skip to content

Commit

Permalink
Merge branch 'chimurai:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
17hz authored Sep 2, 2024
2 parents c8e337b + 45364e4 commit d4513a2
Show file tree
Hide file tree
Showing 22 changed files with 503 additions and 487 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
# Matches the exact files
[{package.json}]
indent_size = 2
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

30 changes: 0 additions & 30 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"deno.enable": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"markdown.extension.toc.levels": "2..3"
}
23 changes: 14 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Changelog

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

- fix(type): fix RequestHandler return type
- refactor(errors): improve pathFilter error message
- 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
- fix(fix-request-body): support '+json' content-type suffix
## next

- refactor(dependency): replace is-plain-obj with is-plain-object
- chore(package): upgrade to eslint v9

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

- fix(type): fix RequestHandler return type ([#980](https://github.com/chimurai/http-proxy-middleware/pull/980))
- refactor(errors): improve pathFilter error message ([#987](https://github.com/chimurai/http-proxy-middleware/pull/987))
- fix(logger-plugin): fix missing target port ([#989](https://github.com/chimurai/http-proxy-middleware/pull/989))
- ci(package): npm package provenance ([#991](https://github.com/chimurai/http-proxy-middleware/pull/1015))
- fix(logger-plugin): log target port when router option is used ([#1001](https://github.com/chimurai/http-proxy-middleware/pull/1001))
- refactor: fix circular dependencies ([#1010](https://github.com/chimurai/http-proxy-middleware/pull/1010))
- fix(fix-request-body): support '+json' content-type suffix ([#1015](https://github.com/chimurai/http-proxy-middleware/pull/1015))

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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,4 @@ $ yarn spellcheck
The MIT License (MIT)
Copyright (c) 2015-2022 Steven Chim
Copyright (c) 2015-2024 Steven Chim
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"restream",
"snyk",
"streamify",
"tseslint",
"typicode",
"vhosted",
"websockets",
Expand Down
49 changes: 49 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';

export default tseslint.config(
// replacement of legacy `.eslintignore`
{
ignores: ['dist'],
},
// extends...
eslint.configs.recommended,
...tseslint.configs.recommended,
eslintPluginPrettierRecommended,
// base config
{
languageOptions: {
globals: {
...globals.node,
},
},
},
{
files: ['**/*.js'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['**/*.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'none', ignoreRestSiblings: false },
],
'prettier/prettier': 'warn',
},
},
{
files: ['src/**/*.ts'],
rules: {
'no-restricted-imports': ['error', { paths: ['express'] }],
},
},
);
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import('jest').Config} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
Expand Down
44 changes: 24 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "http-proxy-middleware",
"version": "3.0.1-beta.1",
"type": "commonjs",
"version": "3.0.1",
"description": "The one-liner node.js proxy middleware for connect, express, next.js and more",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -12,7 +13,7 @@
"install:all": "yarn && (cd examples && yarn)",
"lint": "yarn prettier && yarn eslint",
"lint:fix": "yarn prettier:fix && yarn eslint:fix",
"eslint": "eslint '{src,test}/**/*.ts' --cache",
"eslint": "eslint '{src,test,examples}/**/*.{js,ts}' --cache",
"eslint:fix": "yarn eslint --fix",
"prettier": "prettier --list-different \"**/*.{js,ts,md,yml,json,html}\"",
"prettier:fix": "prettier --write \"**/*.{js,ts,md,yml,json,html}\"",
Expand Down Expand Up @@ -55,42 +56,45 @@
},
"homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
"devDependencies": {
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@commitlint/cli": "19.4.1",
"@commitlint/config-conventional": "19.4.1",
"@eslint/js": "9.9.1",
"@types/debug": "4.1.12",
"@types/eslint": "9.6.1",
"@types/eslint__js": "8.42.3",
"@types/express": "4.17.21",
"@types/is-glob": "4.0.4",
"@types/jest": "29.5.12",
"@types/micromatch": "4.0.9",
"@types/node": "20.14.10",
"@types/node": "22.5.1",
"@types/supertest": "6.0.2",
"@types/ws": "8.5.10",
"@typescript-eslint/eslint-plugin": "7.16.0",
"@typescript-eslint/parser": "7.16.0",
"@types/ws": "8.5.12",
"body-parser": "1.20.2",
"eslint": "8.57.0",
"eslint": "9.9.1",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-prettier": "5.2.1",
"express": "4.19.2",
"get-port": "5.1.1",
"husky": "9.0.11",
"globals": "15.9.0",
"husky": "9.1.5",
"jest": "29.7.0",
"lint-staged": "15.2.7",
"mockttp": "3.14.0",
"lint-staged": "15.2.9",
"mockttp": "3.15.2",
"open": "8.4.2",
"prettier": "3.3.2",
"prettier": "3.3.3",
"supertest": "7.0.0",
"ts-jest": "29.2.2",
"typescript": "5.5.3",
"ts-jest": "29.2.5",
"typescript": "5.5.4",
"typescript-eslint": "8.3.0",
"ws": "8.18.0"
},
"dependencies": {
"@types/http-proxy": "^1.17.14",
"debug": "^4.3.5",
"@types/http-proxy": "^1.17.15",
"debug": "^4.3.6",
"http-proxy": "^1.18.1",
"is-glob": "^4.0.3",
"is-plain-obj": "^3.0.0",
"micromatch": "^4.0.7"
"is-plain-object": "^5.0.0",
"micromatch": "^4.0.8"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
Expand Down
4 changes: 2 additions & 2 deletions src/get-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {

export function getPlugins<TReq, TRes>(options: Options<TReq, TRes>): Plugin<TReq, TRes>[] {
// don't load default errorResponsePlugin if user has specified their own
const maybeErrorResponsePlugin = !!options.on?.error ? [] : [errorResponsePlugin];
const maybeErrorResponsePlugin = options.on?.error ? [] : [errorResponsePlugin];

const defaultPlugins = !!options.ejectPlugins
const defaultPlugins = options.ejectPlugins
? [] // no default plugins when ejecting
: [debugProxyErrorsPlugin, proxyEventsPlugin, loggerPlugin, ...maybeErrorResponsePlugin];
const userPlugins: Plugin<TReq, TRes>[] = options.plugins ?? [];
Expand Down
4 changes: 2 additions & 2 deletions src/http-proxy-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export class HttpProxyMiddleware<TReq, TRes> {
debug(`proxy request to target: %O`, activeProxyOptions.target);
this.proxy.web(req, res, activeProxyOptions);
} catch (err) {
next && next(err);
next?.(err);
}
} else {
next && next();
next?.();
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */

import { Logger, Options } from './types';

/**
Expand Down
6 changes: 3 additions & 3 deletions src/path-rewriter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isPlainObj = require('is-plain-obj');
import { isPlainObject } from 'is-plain-object';
import { ERRORS } from './errors';
import { Debug } from './debug';

Expand Down Expand Up @@ -45,7 +45,7 @@ export function createPathRewriter(rewriteConfig) {
function isValidRewriteConfig(rewriteConfig) {
if (typeof rewriteConfig === 'function') {
return true;
} else if (isPlainObj(rewriteConfig)) {
} else if (isPlainObject(rewriteConfig)) {
return Object.keys(rewriteConfig).length !== 0;
} else if (rewriteConfig === undefined || rewriteConfig === null) {
return false;
Expand All @@ -57,7 +57,7 @@ function isValidRewriteConfig(rewriteConfig) {
function parsePathRewriteRules(rewriteConfig: Record<string, string>) {
const rules: RewriteRule[] = [];

if (isPlainObj(rewriteConfig)) {
if (isPlainObject(rewriteConfig)) {
for (const [key, value] of Object.entries(rewriteConfig)) {
rules.push({
regex: new RegExp(key),
Expand Down
4 changes: 2 additions & 2 deletions src/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isPlainObj = require('is-plain-obj');
import { isPlainObject } from 'is-plain-object';
import { Debug } from './debug';

const debug = Debug.extend('router');
Expand All @@ -7,7 +7,7 @@ export async function getTarget(req, config) {
let newTarget;
const router = config.router;

if (isPlainObj(router)) {
if (isPlainObject(router)) {
newTarget = getTargetFromProxyTable(req, router);
} else if (typeof router === 'function') {
newTarget = await router(req);
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
*/

/* eslint-disable @typescript-eslint/no-empty-interface */

import type * as http from 'http';
import type * as httpProxy from 'http-proxy';
import type * as net from 'net';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/function.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/no-unsafe-function-type */

export function getFunctionName(fn: Function): string {
return fn.name || '[anonymous Function]';
Expand Down
2 changes: 1 addition & 1 deletion test/types.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-unused-expressions */

import * as express from 'express';
import * as http from 'http';
Expand Down
1 change: 0 additions & 1 deletion test/unit/path-filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ describe('Path Filter', () => {
});

it('should not throw error with Function', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(testPathFilter(() => {})).not.toThrowError(Error);
});
});
Expand Down
2 changes: 0 additions & 2 deletions test/unit/path-rewriter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ describe('Path rewriting', () => {
});

it('should not throw when function config is provided', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(badFn(() => {})).not.toThrowError(Error);
});

it('should not throw when async function config is provided', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(badFn(async () => {})).not.toThrowError(Error);
});
});
Expand Down
1 change: 0 additions & 1 deletion test/unit/utils/function.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { getFunctionName } from '../../../src/utils/function';

describe('getFunctionName()', () => {
Expand Down
Loading

0 comments on commit d4513a2

Please sign in to comment.