@ndiinginc/proxy

1.0.14 • Public • Published

Install

npm install @ndiinginc/proxy

EventEmitter

Constructor

EventEmitter()

Methods

EventEmitter#on()
EventEmitter#emit()

Logger

Properties

Logger#id
Logger#logs

Methods

Logger#create()
Logger#read()
Logger#update()
Logger#delete()

Server

Properties

Server#logging
Server#pools

Static Methods

Server.enableProxy()
Enable windows proxy settings `Check proxy`
Server.disableProxy()
Disable windows proxy settings `Check proxy`
Server.createCertificateAuthority()
Create ROOT CA `crt` and `key`, then import to windows trusted root ca
Server.listen()
Server.close()

ProxyServer

Methods

ProxyServer#post()
ProxyServer#get()
ProxyServer#set()
ProxyServer#patch()
ProxyServer#delete()
ProxyServer#use()
ProxyServer#listen()
ProxyServer#close()

Examples

// Create proxy
const proxy1 = new ProxyServer()

// Network monitoring/logging

// (eventName, requestObject)
proxy1.logging.on('request.*', console.log)
// (eventName, responseObject)
proxy1.logging.on('response.*', console.log)
// (eventName, logObject)
// logObject={id,request,response}
proxy1.logging.on('update.*', console.log)

// Start server
proxy1.listen(8888, () => {
    console.log('proxy1 started')
})

// Stop server after
setTimeout(() => {
    proxy1.close()
    console.log('proxy1 stopped')
}, 1000 * 5)

// Create anaother proxy
// it will subscribe with previous active proxy
const proxy2 = new ProxyServer()

// Intercept request and response
// using `use` function for global `request.method`
// and post,get,patch,put,delete for spesific `request.method`
// it's not like router middleware
proxy2.use('https://jsonplaceholder.typicode.com/posts', (req,res,next) => {
    // this callback will call twice
    // on before request
    if(req){
        // intercept req
        delete req.headers['if-none-match'] // remove cache
    }
    // and before response
    if(res){
        // intercept res
        res.body = JSON.stringify([]) // response with empty json array
    }
    // then continue request/response
    // with `next` callback method
    next()
})

// Start server
// when previous proxy still active
// this method never been call
// so the port are still the saame
proxy2.listen(8888, () => {
    console.log('proxy2 started')
})

// Stop server after
// also it never been stop until all proxy are stopped
setTimeout(() => {
    proxy2.close()
    console.log('proxy2 stopped')
}, 1000 * 10)

// and thats it, just simple like that

Package Sidebar

Install

npm i @ndiinginc/proxy

Weekly Downloads

2

Version

1.0.14

License

MIT

Unpacked Size

24.7 kB

Total Files

5

Last publish

Collaborators

  • ndiinginc