Connect Proxy Middleware

0.15.0 · abandoned · verified Tue Apr 21

proxy-middleware offers a basic HTTP(S) proxy capability designed as middleware for the Connect framework. It enables developers to configure specific URL paths that forward incoming requests to an alternate target URL, supporting both HTTP and HTTPS protocols. The package's latest stable version is 0.15.0. It integrates directly into the Connect framework, a popular Node.js web framework from an earlier era. Given its age (last updated in 2016), the package is effectively abandoned, meaning it receives no further updates, security patches, or feature enhancements. This significantly limits its utility and makes it unsuitable for new projects or production environments in modern Node.js ecosystems, which have moved towards more feature-rich and actively maintained alternatives like `http-proxy-middleware` or `node-http-proxy`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up a Connect server with `proxy-middleware` to forward requests from `/api` to a local target server running on port 9000.

const connect = require('connect');
const url = require('url');
const proxy = require('proxy-middleware');
const http = require('http');

// Create a simple target server for the proxy to forward requests to
const targetServer = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end(`Hello from target server! Path: ${req.url}\n`);
});

targetServer.listen(9000, () => {
  console.log('Target server listening on http://localhost:9000');

  const app = connect();

  // Configure the proxy route: requests to /api will go to http://localhost:9000/target-prefix
  const proxyOptions = url.parse('http://localhost:9000/target-prefix');
  app.use('/api', proxy(proxyOptions));

  // Add a simple route to the main app to show it's working
  app.use('/', (req, res) => {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Main app. Try /api/hello to see the proxy in action.\n');
  });

  const port = 3000;
  http.createServer(app).listen(port, () => {
    console.log(`Connect server running on http://localhost:${port}`);
    console.log('Test with:');
    console.log(`  curl http://localhost:${port}/`);
    console.log(`  curl http://localhost:${port}/api/some/path`);
    console.log(`Expected output for /api/some/path: "Hello from target server! Path: /target-prefix/some/path"`);
  });
});

view raw JSON →