Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-proxy-middleware

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-proxy-middleware - npm Package Compare versions

Comparing version 0.22.0-alpha to 1.0.0

8

CHANGELOG.md
# Changelog
## [v1.0.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v1.0.0)
- feat(createProxyMiddleware): explicit import http-proxy-middleware (BREAKING CHANGE)([#400](https://github.com/chimurai/http-proxy-middleware/issues/400#issuecomment-587162378))
- feat(typescript): export http-proxy-middleware types ([#400](https://github.com/chimurai/http-proxy-middleware/issues/400))
- fix(typescript): ES6 target - TS1192 ([#400](https://github.com/chimurai/http-proxy-middleware/issues/400#issuecomment-587064349))
## [v0.21.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.21.0)
- feat(http-proxy): bump to v1.18.0
- feat: async router ([#379](https://github.com/chimurai/http-proxy-middleware/issues/335)) ([LiranBri](https://github.com/LiranBri))
- feat: async router ([#379](https://github.com/chimurai/http-proxy-middleware/issues/379)) ([LiranBri](https://github.com/LiranBri))
- feat(typescript): types support ([#369](https://github.com/chimurai/http-proxy-middleware/pull/369))

@@ -8,0 +14,0 @@ - feat: async pathRewrite ([#397](https://github.com/chimurai/http-proxy-middleware/pull/397)) ([rsethc](https://github.com/rsethc))

9

dist/handlers.js

@@ -16,10 +16,3 @@ "use strict";

// https://github.com/nodejitsu/node-http-proxy#listening-for-proxy-events
const proxyEvents = [
'error',
'proxyReq',
'proxyReqWs',
'proxyRes',
'open',
'close'
];
const proxyEvents = ['error', 'proxyReq', 'proxyReqWs', 'proxyRes', 'open', 'close'];
const handlers = {};

@@ -26,0 +19,0 @@ for (const event of proxyEvents) {

@@ -1,2 +0,2 @@

import { Filter, IRequestHandler, Options } from './types';
import { Filter, RequestHandler, Options } from './types';
export declare class HttpProxyMiddleware {

@@ -10,3 +10,3 @@ private logger;

constructor(context: Filter | Options, opts?: Options);
middleware: IRequestHandler;
middleware: RequestHandler;
private catchUpgradeRequest;

@@ -13,0 +13,0 @@ private handleUpgrade;

import { Filter, Options } from './types';
export declare function createProxyMiddleware(context: Filter | Options, options?: Options): import("./types").IRequestHandler;
export { Options } from './types';
export declare function createProxyMiddleware(context: Filter | Options, options?: Options): import("./types").RequestHandler;
export { Filter, Options, RequestHandler } from './types';

@@ -6,25 +6,25 @@ /// <reference types="node" />

import * as net from 'net';
export interface IRequest extends express.Request {
export interface Request extends express.Request {
}
export interface IResponse extends express.Response {
export interface Response extends express.Response {
}
export interface IRequestHandler extends express.RequestHandler {
upgrade?: (req: IRequest, socket: net.Socket, head: any) => void;
export interface RequestHandler extends express.RequestHandler {
upgrade?: (req: Request, socket: net.Socket, head: any) => void;
}
export declare type Filter = string | string[] | ((pathname: string, req: IRequest) => boolean);
export declare type Filter = string | string[] | ((pathname: string, req: Request) => boolean);
export interface Options extends httpProxy.ServerOptions {
pathRewrite?: {
[regexp: string]: string;
} | ((path: string, req: IRequest) => string) | ((path: string, req: IRequest) => Promise<string>);
} | ((path: string, req: Request) => string) | ((path: string, req: Request) => Promise<string>);
router?: {
[hostOrPath: string]: string;
} | ((req: IRequest) => string) | ((req: IRequest) => Promise<string>);
} | ((req: Request) => string) | ((req: Request) => Promise<string>);
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
logProvider?(provider: LogProvider): LogProvider;
onError?(err: Error, req: IRequest, res: IResponse): void;
onProxyRes?(proxyRes: http.ServerResponse, req: IRequest, res: IResponse): void;
onProxyReq?(proxyReq: http.ClientRequest, req: IRequest, res: IResponse): void;
onProxyReqWs?(proxyReq: http.ClientRequest, req: IRequest, socket: net.Socket, options: httpProxy.ServerOptions, head: any): void;
onError?(err: Error, req: Request, res: Response): void;
onProxyRes?(proxyRes: http.ServerResponse, req: Request, res: Response): void;
onProxyReq?(proxyReq: http.ClientRequest, req: Request, res: Response): void;
onProxyReqWs?(proxyReq: http.ClientRequest, req: Request, socket: net.Socket, options: httpProxy.ServerOptions, head: any): void;
onOpen?(proxySocket: net.Socket): void;
onClose?(res: IResponse, socket: net.Socket, head: any): void;
onClose?(res: Response, socket: net.Socket, head: any): void;
}

@@ -31,0 +31,0 @@ interface LogProvider {

{
"name": "http-proxy-middleware",
"version": "0.22.0-alpha",
"version": "1.0.0",
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync",

@@ -51,3 +51,3 @@ "main": "dist/index.js",

},
"homepage": "https://github.com/chimurai/http-proxy-middleware",
"homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
"devDependencies": {

@@ -54,0 +54,0 @@ "@commitlint/cli": "^8.0.0",

@@ -13,2 +13,9 @@ # http-proxy-middleware

## ⚠️ Note
This page is showing documentation for version v1.x.x ([release notes](https://github.com/chimurai/http-proxy-middleware/releases))
If you're looking for v0.x documentation. Go to:
https://github.com/chimurai/http-proxy-middleware/tree/v0.21.0#readme
## TL;DR

@@ -19,11 +26,10 @@

```javascript
var express = require('express');
var proxy = require('http-proxy-middleware');
// javascript
var app = express();
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
app.use(
'/api',
proxy({ target: 'http://www.example.org', changeOrigin: true })
);
const app = express();
app.use('/api', createProxyMiddleware({ target: 'http://www.example.org', changeOrigin: true }));
app.listen(3000);

@@ -34,2 +40,16 @@

```typescript
// typescript
import * as express from 'express';
import { createProxyMiddleware, Filter, Options, RequestHandler } from 'http-proxy-middleware';
const app = express();
app.use('/api', createProxyMiddleware({ target: 'http://www.example.org', changeOrigin: true }));
app.listen(3000);
// http://localhost:3000/api/foo/bar -> http://www.example.org/api/foo/bar
```
_All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#options) can be used, along with some extra `http-proxy-middleware` [options](#options).

@@ -74,11 +94,11 @@

#### proxy([context,] config)
#### createProxyMiddleware([context,] config)
```javascript
var proxy = require('http-proxy-middleware');
const { createProxyMiddleware } = require('http-proxy-middleware');
var apiProxy = proxy('/api', { target: 'http://www.example.org' });
// \____/ \_____________________________/
// | |
// context options
const apiProxy = createProxyMiddleware('/api', { target: 'http://www.example.org' });
// \____/ \_____________________________/
// | |
// context options

@@ -94,7 +114,7 @@ // 'apiProxy' is now ready to be used as middleware in a server.

#### proxy(uri [, config])
#### createProxyMiddleware(uri [, config])
```javascript
// shorthand syntax for the example above:
var apiProxy = proxy('http://www.example.org/api');
const apiProxy = createProxyMiddleware('http://www.example.org/api');
```

@@ -110,7 +130,7 @@

// include dependencies
var express = require('express');
var proxy = require('http-proxy-middleware');
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
// proxy middleware options
var options = {
const options = {
target: 'http://www.example.org', // target host

@@ -131,6 +151,6 @@ changeOrigin: true, // needed for virtual hosted sites

// create the proxy (without context)
var exampleProxy = proxy(options);
const exampleProxy = createProxyMiddleware(options);
// mount `exampleProxy` in web server
var app = express();
const app = express();
app.use('/api', exampleProxy);

@@ -155,9 +175,9 @@ app.listen(3000);

- `proxy({...})` - matches any path, all requests will be proxied.
- `proxy('/', {...})` - matches any path, all requests will be proxied.
- `proxy('/api', {...})` - matches paths starting with `/api`
- `createProxyMiddleware({...})` - matches any path, all requests will be proxied.
- `createProxyMiddleware('/', {...})` - matches any path, all requests will be proxied.
- `createProxyMiddleware('/api', {...})` - matches paths starting with `/api`
- **multiple path matching**
- `proxy(['/api', '/ajax', '/someotherpath'], {...})`
- `createProxyMiddleware(['/api', '/ajax', '/someotherpath'], {...})`

@@ -168,8 +188,8 @@ - **wildcard path matching**

- `proxy('**', {...})` matches any path, all requests will be proxied.
- `proxy('**/*.html', {...})` matches any path which ends with `.html`
- `proxy('/*.html', {...})` matches paths directly under path-absolute
- `proxy('/api/**/*.html', {...})` matches requests ending with `.html` in the path of `/api`
- `proxy(['/api/**', '/ajax/**'], {...})` combine multiple patterns
- `proxy(['/api/**', '!**/bad.json'], {...})` exclusion
- `createProxyMiddleware('**', {...})` matches any path, all requests will be proxied.
- `createProxyMiddleware('**/*.html', {...})` matches any path which ends with `.html`
- `createProxyMiddleware('/*.html', {...})` matches paths directly under path-absolute
- `createProxyMiddleware('/api/**/*.html', {...})` matches requests ending with `.html` in the path of `/api`
- `createProxyMiddleware(['/api/**', '/ajax/**'], {...})` combine multiple patterns
- `createProxyMiddleware(['/api/**', '!**/bad.json'], {...})` exclusion

@@ -186,7 +206,9 @@ **Note**: In multiple path matching, you cannot use string paths and wildcard paths together.

*/
var filter = function(pathname, req) {
const filter = function(pathname, req) {
return pathname.match('^/api') && req.method === 'GET';
};
var apiProxy = proxy(filter, { target: 'http://www.example.org' });
const apiProxy = createProxyMiddleware(filter, {
target: 'http://www.example.org'
});
```

@@ -215,3 +237,3 @@

pathRewrite: async function (path, req) {
var should_add_something = await httpRequestToDecideSomething(path);
const should_add_something = await httpRequestToDecideSomething(path);
if (should_add_something) path += "something";

@@ -262,5 +284,5 @@ return path;

function logProvider(provider) {
var logger = new (require('winston').Logger)();
const logger = new (require('winston').Logger)();
var myCustomProvider = {
const myCustomProvider = {
log: logger.log,

@@ -287,5 +309,3 @@ debug: logger.debug,

});
res.end(
'Something went wrong. And we are reporting a custom error message.'
);
res.end('Something went wrong. And we are reporting a custom error message.');
}

@@ -417,10 +437,10 @@ ```

```javascript
proxy('http://www.example.org:8000/api');
// proxy('/api', {target: 'http://www.example.org:8000'});
createProxyMiddleware('http://www.example.org:8000/api');
// createProxyMiddleware('/api', {target: 'http://www.example.org:8000'});
proxy('http://www.example.org:8000/api/books/*/**.json');
// proxy('/api/books/*/**.json', {target: 'http://www.example.org:8000'});
createProxyMiddleware('http://www.example.org:8000/api/books/*/**.json');
// createProxyMiddleware('/api/books/*/**.json', {target: 'http://www.example.org:8000'});
proxy('http://www.example.org:8000/api', { changeOrigin: true });
// proxy('/api', {target: 'http://www.example.org:8000', changeOrigin: true});
createProxyMiddleware('http://www.example.org:8000/api', { changeOrigin: true });
// createProxyMiddleware('/api', {target: 'http://www.example.org:8000', changeOrigin: true});
```

@@ -434,6 +454,3 @@

```javascript
app.use(
'/api',
proxy({ target: 'http://www.example.org', changeOrigin: true })
);
app.use('/api', createProxyMiddleware({ target: 'http://www.example.org', changeOrigin: true }));
```

@@ -451,9 +468,9 @@

// verbose api
proxy('/', { target: 'http://echo.websocket.org', ws: true });
createProxyMiddleware('/', { target: 'http://echo.websocket.org', ws: true });
// shorthand
proxy('http://echo.websocket.org', { ws: true });
createProxyMiddleware('http://echo.websocket.org', { ws: true });
// shorter shorthand
proxy('ws://echo.websocket.org');
createProxyMiddleware('ws://echo.websocket.org');
```

@@ -466,8 +483,8 @@

```javascript
var wsProxy = proxy('ws://echo.websocket.org', { changeOrigin: true });
const wsProxy = createProxyMiddleware('ws://echo.websocket.org', { changeOrigin: true });
var app = express();
const app = express();
app.use(wsProxy);
var server = app.listen(3000);
const server = app.listen(3000);
server.on('upgrade', wsProxy.upgrade); // <-- subscribe to http 'upgrade'

@@ -474,0 +491,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc