Simple Local HTTPS Proxy

2.0.5 · active · verified Wed Apr 22

local-ssl-proxy is a lightweight utility designed to create an HTTPS proxy for local development. It leverages a self-signed SSL certificate, allowing developers to access local HTTP servers over HTTPS. This functionality is critical for testing applications that require a secure context, such as those using OAuth, secure cookies, geolocation APIs, or needing to avoid mixed-content warnings. The current stable version is 2.0.5, last updated in March 2023. While specific release cadence isn't formalized, updates typically address dependencies or minor enhancements. Its primary differentiators are its ease of use via the command line for quick setup, support for custom certificates (e.g., generated by `mkcert` for a trusted browser experience), and the ability to manage multiple proxy configurations through a single file, making it a flexible choice for diverse local development workflows. It is strictly intended for local development and should never be used in production environments.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to programmatically start `local-ssl-proxy` to proxy HTTPS traffic from port 9001 to an underlying HTTP server on port 3000. It also shows the equivalent CLI command. This setup is ideal for local development and requires pre-generated `mkcert` certificates for a trusted experience.

import { start } from 'local-ssl-proxy';
import http from 'http';

// Start a simple HTTP server on port 3000
const httpServer = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello from HTTP server on port 3000!');
});
httpServer.listen(3000, () => {
  console.log('HTTP server running on http://localhost:3000');
});

// Start local-ssl-proxy to proxy HTTPS (9001) to HTTP (3000)
// You'll likely need to generate trusted certs with mkcert first:
// mkcert -install && mkcert localhost
start({
  source: 9001,
  target: 3000,
  key: 'localhost-key.pem', // Path to your generated key
  cert: 'localhost.pem'   // Path to your generated cert
})
  .then(() => {
    console.log('HTTPS proxy running on https://localhost:9001');
    console.log('Access your HTTP server via https://localhost:9001');
  })
  .catch(err => {
    console.error('Failed to start proxy:', err.message);
    process.exit(1);
  });

// CLI equivalent (run in terminal):
// npx local-ssl-proxy --source 9001 --target 3000 --key localhost-key.pem --cert localhost.pem

view raw JSON →