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

express-http-proxy

Package Overview
Dependencies
Maintainers
3
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-http-proxy

http proxy middleware for express

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
565K
increased by13.57%
Maintainers
3
Weekly downloads
 
Created

What is express-http-proxy?

The express-http-proxy package is a middleware for Express.js that allows you to easily proxy HTTP requests to another server. It is useful for creating APIs that aggregate data from multiple sources, handling cross-origin requests, and more.

What are express-http-proxy's main functionalities?

Basic Proxying

This feature allows you to proxy requests from your Express server to another server. In this example, any request to '/proxy' will be forwarded to 'http://example.com'.

const express = require('express');
const proxy = require('express-http-proxy');
const app = express();

app.use('/proxy', proxy('http://example.com'));

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Customizing Proxy Requests

This feature allows you to customize the path of the proxied request. In this example, any request to '/proxy' will be forwarded to 'http://example.com/api' with the original request URL appended.

const express = require('express');
const proxy = require('express-http-proxy');
const app = express();

app.use('/proxy', proxy('http://example.com', {
  proxyReqPathResolver: function(req) {
    return '/api' + req.url;
  }
}));

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Handling Proxy Responses

This feature allows you to modify the response from the proxied server before sending it back to the client. In this example, the word 'example' in the response body is replaced with 'sample'.

const express = require('express');
const proxy = require('express-http-proxy');
const app = express();

app.use('/proxy', proxy('http://example.com', {
  userResDecorator: function(proxyRes, proxyResData, userReq, userRes) {
    return proxyResData.toString('utf8').replace('example', 'sample');
  }
}));

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Other packages similar to express-http-proxy

Keywords

FAQs

Package last updated on 08 Aug 2024

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