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

@types/http-proxy-middleware

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/http-proxy-middleware

TypeScript definitions for http-proxy-middleware

  • 0.17.0
  • npm
  • Socket score

Version published
Weekly downloads
227K
decreased by-8.2%
Maintainers
1
Weekly downloads
 
Created

What is @types/http-proxy-middleware?

@types/http-proxy-middleware provides TypeScript type definitions for the http-proxy-middleware package, which is used to create a proxy middleware for connecting, redirecting, and modifying HTTP requests in a Node.js application.

What are @types/http-proxy-middleware's main functionalities?

Basic Proxy Setup

This feature allows you to set up a basic proxy middleware that forwards requests from '/api' to 'http://www.example.org'. The 'changeOrigin' option modifies the origin of the host header to the target URL.

const { createProxyMiddleware } = require('http-proxy-middleware');

const apiProxy = createProxyMiddleware('/api', { target: 'http://www.example.org', changeOrigin: true });

module.exports = function(app) {
  app.use(apiProxy);
};

Path Rewriting

This feature allows you to rewrite the URL path before forwarding the request. In this example, requests to '/api' will be forwarded to 'http://www.example.org' with the '/api' prefix removed.

const { createProxyMiddleware } = require('http-proxy-middleware');

const apiProxy = createProxyMiddleware('/api', {
  target: 'http://www.example.org',
  pathRewrite: { '^/api': '' },
  changeOrigin: true
});

module.exports = function(app) {
  app.use(apiProxy);
};

Custom Proxy Configuration

This feature allows you to customize the proxy request by adding custom headers or modifying the request in other ways. In this example, a custom header 'X-Special-Proxy-Header' is added to the proxied request.

const { createProxyMiddleware } = require('http-proxy-middleware');

const apiProxy = createProxyMiddleware('/api', {
  target: 'http://www.example.org',
  changeOrigin: true,
  onProxyReq: (proxyReq, req, res) => {
    // Add custom header to request
    proxyReq.setHeader('X-Special-Proxy-Header', 'foobar');
  }
});

module.exports = function(app) {
  app.use(apiProxy);
};

Other packages similar to @types/http-proxy-middleware

FAQs

Package last updated on 18 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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