Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chimurai/http-proxy-middleware
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.6
Choose a base ref
...
head repository: chimurai/http-proxy-middleware
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.7
Choose a head ref
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on Oct 6, 2024

  1. ci(github actions): add publish.yml

    chimurai committed Oct 6, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    pellared Robert Pająk
    Copy the full SHA
    1bd6dd5 View commit details
  2. fix(filter): handle errors

    chimurai committed Oct 6, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    pellared Robert Pająk
    Copy the full SHA
    0b4274e View commit details
  3. chore(package): v2.0.7

    chimurai committed Oct 6, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    pellared Robert Pająk
    Copy the full SHA
    90afb7c View commit details
  4. ci(github-actions): fix npm tag

    chimurai committed Oct 6, 2024
    Copy the full SHA
    1e92339 View commit details
Showing with 74 additions and 3 deletions.
  1. +33 −0 .github/workflows/publish.yml
  2. +5 −0 CHANGELOG.md
  3. +1 −1 package.json
  4. +7 −2 src/http-proxy-middleware.ts
  5. +28 −0 test/e2e/http-proxy-middleware.spec.ts
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: publish to npmjs
on:
release:
types: [prereleased, released]
jobs:
build-and-publish:
# prevents this action from running on forks
if: github.repository == 'chimurai/http-proxy-middleware'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
run: yarn install

- name: Publish to NPM (beta)
if: 'github.event.release.prerelease'
run: npm publish --provenance --access public --tag v2-beta
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to NPM (stable)
if: '!github.event.release.prerelease'
run: npm publish --provenance --access public --tag v2-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

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

- ci(github actions): add publish.yml
- fix(filter): handle errors

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

- fix(proxyReqWs): catch socket errors ([#763](https://github.com/chimurai/http-proxy-middleware/pull/763))
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-proxy-middleware",
"version": "2.0.6",
"version": "2.0.7",
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync",
"main": "dist/index.js",
"types": "dist/index.d.ts",
9 changes: 7 additions & 2 deletions src/http-proxy-middleware.ts
Original file line number Diff line number Diff line change
@@ -109,8 +109,13 @@ export class HttpProxyMiddleware {
* @return {Boolean}
*/
private shouldProxy = (context, req: Request): boolean => {
const path = req.originalUrl || req.url;
return contextMatcher.match(context, path, req);
try {
const path = req.originalUrl || req.url;
return contextMatcher.match(context, path, req);
} catch (error) {
this.logger.error(error);
return false;
}
};

/**
28 changes: 28 additions & 0 deletions test/e2e/http-proxy-middleware.spec.ts
Original file line number Diff line number Diff line change
@@ -153,6 +153,34 @@ describe('E2E http-proxy-middleware', () => {
const response = await agent.get(`/api/b/c/d`).expect(404);
expect(response.status).toBe(404);
});

it('should not proxy when filter throws Error', async () => {
const myError = new Error('MY_ERROR');
const filter = (path, req) => {
throw myError;
};

const logger = {
log: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};

agent = request(
createApp(
createProxyMiddleware(filter, {
target: `http://localhost:${mockTargetServer.port}`,
logProvider: () => logger,
})
)
);

await mockTargetServer.get('/api/b/c/d').thenReply(200, 'HELLO WEB');
const response = await agent.get(`/api/b/c/d`).expect(404);
expect(response.status).toBe(404);
expect(logger.error).toHaveBeenCalledWith(expect.objectContaining(myError));
});
});

describe('multi path', () => {