Git Product home page Git Product logo

debugging-proxy's Introduction

node-debugging-proxy

NPM

A simple HTTP proxy that proxies HTTP and HTTPS requests transparently. Useful for debugging that your application works correctly with proxies.

Installation

npm i -g @cypress/debugging-proxy

## or, if you prefer yarn
yarn global add @cypress/debugging-proxy

Usage (as a standalone server)

Start the proxy on port 1337

debugging-proxy

Use a custom port

PORT=1234 debugging-proxy

Show logs of all requests

DEBUG=proxy debugging-proxy

Require HTTP Basic Auth for proxy access

PROXY_USER=some-username PROXY_PASS=some-password debugging-proxy

Spawn an HTTPS proxy using a custom key and cert

HTTPS_KEY=/path/to/key.key HTTPS_CERT=/path/to/cert.pem debugging-proxy

Usage (as a module, in a test)

const debugProxy = require('@cypress/debugging-proxy')

// create an instance
const proxy = new debugProxy({
    auth: { // if `auth` is set, HTTP basic authentication to the proxy will be required using these credentials
        username: 'foo',
        password: 'bar'
    },
    keepRequests: false, // if `keepRequests` is set, the proxy will store a log of requests that can be retrieved using `proxy.getRequests()`
    https: { // if https is set, https.createServer will be called with this key and cert to launch the server
        key: fs.readFileSync('my-key.pem'),
        cert: fs.readFileSync('my-cert.pem')
    }
})

// using your stubbing/spying library of choice...
spy(proxy.proxyRequestToUrl)
spy(proxy.proxySslConnectionToDomain)

// start an httpproxy on localhost:3000
proxy.start(3000).then(() => {
    // make some requests using the proxy at localhost:3000, then...
    expect(proxy.proxyRequestToUrl).to.be.calledWith('http://google.com')
    expect(proxy.proxySslConnectionToDomain).to.be.calledWith('google.com')

    expect(proxy.getRequests().find(incomingMessage => incomingMessage.ssl === false)).to.exist

    // clean up
    proxy.stop().then(() => {
        console.log('All done!')
    })
})

debugging-proxy's People

Contributors

brian-mann avatar flotwig avatar renovate-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.