0.5.25 • Published 6 months ago

@wooksjs/http-proxy v0.5.25

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Wooks Proxy

!!! This is work-in-progress library, breaking changes are expected !!!

Wooks Proxy is composable proxy for @wooksjs/event-http

šŸ”„ An easy way to proxy request!

Installation

npm install @wooksjs/http-proxy

Usage

import { useProxy } from '@wooksjs/http-proxy'
app.get('/to-proxy', () => {
  const proxy = useProxy()
  return proxy('https://target-website.com/target-path?query=123')
})

Restrict cookies/headers to pass

import { useProxy } from '@wooksjs/http-proxy'
app.get('/to-proxy', () => {
  const proxy = useProxy()
  return proxy('https://target-website.com/target-path?query=123', {
    reqHeaders: { block: ['referer'] }, // block referer header
    reqCookies: { block: '*' }, // block all req cookies
  })
})

Change response

It's easy as proxy returns fetch response

import { useProxy } from '@wooksjs/http-proxy'
app.get('/to-proxy', async () => {
  const proxy = useProxy()
  const response = proxy('https://mayapi.com/json-api')
  const data = { ...(await response.json()), newField: 'new value' }
  return data
})

Proxy advanced options

import { useProxy } from '@wooksjs/http-proxy'
import { useRequest } from '@wooksjs/composables'
//...
app.get('*', async () => {
  const proxy = useProxy()
  const { url } = useRequest()
  const fetchResponse = await proxy('https://www.google.com' + url, {
    // optional method, be default is set with
    // the original request method
    method: 'GET',

    // the next four options help to filter out
    // request/response headers/cookies
    // each of the option accepts an object with:
    // - allow: '*' | (string | RegExp)[] - a list to allow (default '*')
    // - block: '*' | (string | RegExp)[] - a list to block
    // - overwrite: Record<string| string> | ((data: object) -> object) - object or fn to overwrite data
    reqHeaders: { block: ['referer'] },
    reqCookies: { allow: ['cookie-to-pass-upstream'] },
    resHeaders: { overwrite: { 'x-proxied-by': 'wooks-proxy' } },
    resCookies: { allow: ['cookie-to-pass-downstream'] },

    // debug: true - will print proxy paths and headers/cookies
    debug: true,
  })
  return fetchResponse // fetch response is supported, the body will be downstreamed

  // > you can also return fully buffered body as Uint8Array
  // return new Uint8Array(await fetchResponse.arrayBuffer())

  // > or as string
  // return fetchResponse.text()

  // > or change response before return
  // const data = await fetchResponse.text() + '<new data>'
  // return data
})
//...

Documentation

To check out docs, visit wooks.moost.org.

0.5.25

6 months ago

0.5.20

6 months ago

0.5.18

7 months ago

0.5.19

6 months ago

0.5.17

7 months ago

0.5.16

7 months ago

0.5.15

7 months ago

0.5.14

7 months ago

0.5.13

12 months ago

0.5.10

12 months ago

0.5.11

12 months ago

0.5.12

12 months ago

0.4.37

1 year ago

0.4.36

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.6

12 months ago

0.5.5

1 year ago

0.5.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.8

12 months ago

0.5.7

12 months ago

0.5.9

12 months ago

0.4.35

1 year ago

0.4.33

1 year ago

0.4.34

1 year ago

0.4.31

1 year ago

0.4.32

1 year ago

0.4.30

1 year ago

0.4.28

1 year ago

0.4.29

1 year ago

0.4.27

1 year ago

0.4.26

1 year ago

0.4.24

1 year ago

0.4.23

1 year ago

0.4.22

1 year ago

0.4.20

1 year ago

0.4.21

1 year ago

0.4.19

1 year ago

0.4.18

1 year ago

0.4.17

1 year ago

0.4.15

1 year ago

0.4.16

1 year ago

0.4.14

1 year ago

0.4.13

2 years ago

0.4.12

2 years ago

0.4.10

2 years ago

0.4.11

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.9

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.2.23

2 years ago

0.2.22

2 years ago

0.2.21

2 years ago

0.2.20

2 years ago

0.2.19

2 years ago

0.3.0

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.18

2 years ago

0.2.17

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.1.0

3 years ago