Socket
Socket
Sign inDemoInstall

@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

Stub TypeScript definitions entry for http-proxy-middleware, which provides its own types definitions


Version published
Weekly downloads
191K
increased by0.71%
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 08 Mar 2021

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