Skip to content

A lightweight local HTTPS proxy library for Nest framework apps (Express or Fastify) ๐Ÿ”€

License

Notifications You must be signed in to change notification settings

rbonestell/nest-local-https-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

52 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Nest Logo

A lightweight local HTTPS proxy library for Nest framework apps (Express or Fastify) ๐Ÿ”€

NPM Version Build Status Test Results Test Coverage GitHub License

Description

A lightweight local HTTPS proxy library for Nest framework apps, supporting both Express and Fastify HTTP adapters, designed for use with self-signed SSL certificates.

โš  Disclaimer

This library is intended only for use in local development, testing, and troubleshooting with self-signed SSL certificates. It is not recommended to use this in any production context or public-facing environment.

Always follow best practices when managing SSL certificates for any public-facing or production environment.

Self-signed SSL Certificates

See the following gist for info on creating self-signed SSL certificate PEM files using openssl:

Installation

$ npm i nest-local-https-proxy

Implementation

  1. Load your certificate and private key files into an HTTPS options (SecureContextOptions) object.

    const certPath = './cert.pem';
    const keyPath = './key.pem';
    let httpsOptions: SecureContextOptions;
    // Confirm local certificate files exist
    if (fs.existsSync(certPath) && fs.existsSync(keyPath)) {
      httpsOptions = {
        cert: fs.readFileSync(certPath),
        key: fs.readFileSync(keyPath),
      };
    } else {
      console.log('Failed to initalize HTTPS certificates for local SSL proxy');
    }
  2. Instatiate the LocalHttpsProxy class, providing your NestApplication instance, and the HTTPS options object.

    const httpsDevProxy = new LocalHttpsProxy(app, httpsOptions);
  3. (Optional) Provide callback functions to constructor or subscribe to events on LocalHttpsProxy instance.

    • Provide callback functions to constructor:

      const errorCallback = (error) => { console.error(`HTTPS proxy error occurred: ${error.message}`); };
      const listeningCallback = (httpsPort) => { console.log(`HTTPS listening on ${httpsPort}`); };
      const httpsDevProxy = new LocalHttpsProxy(app, httpsOptions, errorCallback, listeningCallback);
    • Subscribe to events:

      httpsDevProxy.on('listening', (httpsPort) => {
        console.log(`HTTPS listening on ${httpsPort}`);
      });
      httpsDevProxy.on('error', (error) => {
        console.error(`HTTPS proxy error occurred: ${error.message}`);
      });
  4. Start the proxy

    httpsDevProxy.start(port);

Test

# unit tests
$ npm run test

# test coverage
$ npm run test:cov

License

The nest-local-https-proxy project is MIT licensed.

About

A lightweight local HTTPS proxy library for Nest framework apps (Express or Fastify) ๐Ÿ”€

Resources

License

Stars

Watchers

Forks

Packages

No packages published