• Stars
    star
    153
  • Rank 243,368 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a [email protected] proxy middleware

Koa Proxies

NPM

Node.js CI Coverage NPM Downloads Greenkeeper badge

[email protected]/next middlware for http proxy

Powered by http-proxy.

Installation

$ npm install koa-proxies --save

Options

http-proxy events

options.events = {
  error (err, req, res) { },
  proxyReq (proxyReq, req, res) { },
  proxyRes (proxyRes, req, res) { }
}

log option

// enable log
options.logs = true; // or false

// custom log function
options.logs = (ctx, target) {
  console.log('%s - %s %s proxy to -> %s', new Date().toISOString(), ctx.req.method, ctx.req.oldPath, new URL(ctx.req.url, target))
} 

Usage

// dependencies
const Koa = require('koa')
const proxy = require('koa-proxies')
const httpsProxyAgent = require('https-proxy-agent')

const app = new Koa()

// middleware
app.use(proxy('/octocat', {
  target: 'https://api.github.com/users',    
  changeOrigin: true,
  agent: new httpsProxyAgent('http://1.2.3.4:88'), // if you need or just delete this line
  rewrite: path => path.replace(/^\/octocat(\/|\/\w+)?$/, '/vagusx'),
  logs: true
}))

Attention

Please make sure that koa-proxies is in front of koa-bodyparser to avoid this issue 55

const Koa = require('koa')
const app = new Koa()
const proxy = require('koa-proxies')
const bodyParser = require('koa-bodyparser')

app.use(proxy('/user', {
  target: 'http://example.com',    
  changeOrigin: true
}))

app.use(bodyParser())

JavaScript Style Guide

More Repositories

1

webpack-svg-sprite-sample

a webpack SVG sprite sample when using Vue and React
JavaScript
20
star
2

react-pdf-reader

a react pdf viewer based on pdf.js, demo:
JavaScript
7
star
3

postcss-bgc-rgba-fallback

postcss plugin for background rgba polyfill
JavaScript
4
star
4

react-headstream

a react boilerplate
CSS
4
star
5

egg-ts-graphql

TypeScript
3
star
6

blog-deprecated

pure text to note down something
3
star
7

blog

TypeScript
2
star
8

you-dont-need-selenium

puppeteer e2e cheatsheet
Ruby
2
star
9

html-imports-loader

HTML Imports Loader for Webpack
JavaScript
2
star
10

tooltips.css

a pure css implement for tooltips
CSS
2
star
11

cefoselis

a pure js slider across PC and mobile
2
star
12

check-it-out

Yo Yo Check it Out 🐶
2
star
13

io

2
star
14

leoric-browser-with-sql.js

demo
JavaScript
2
star
15

antd-codemod-fixtures

JavaScript
2
star
16

chrome-ext-tm

chrome extension template bulit with rollup and typescript
2
star
17

awesome-vagusX

A collection of awesome things by vagusX
Shell
2
star
18

material-design-color-picker

color vars for material design by stylus
CSS
2
star
19

es-compatible-loader

webpack loader for check es compatiblity for dependencies especially for node_modules
JavaScript
2
star
20

antd4-bundle-analysis

TypeScript
2
star
21

redux-soga

redux?! soga~
1
star
22

lithe-localcache

JavaScript
1
star
23

pdfjs2Host

pdfjs build files to host react pdf reader
JavaScript
1
star
24

html-text-content-rs

JavaScript
1
star
25

welcome-to-my-life

lifecyle container for stateless component
1
star
26

awesome-openai-prompts

1
star
27

node-rs-parquet

TypeScript
1
star
28

umi-browserslist-extends-bug-sample

TypeScript
1
star
29

test-repo1

1
star
30

postcss-background-inlinesvg

1
star
31

rollleft

TypeScript
1
star
32

react-webpack2-boilerplate

personal react webpack2 boilerplate
JavaScript
1
star
33

react-start

start for react
JavaScript
1
star
34

polymer-cnode

a cnodejs web client app based on Google Polymer
1
star
35

yet-another-blog

JavaScript
1
star
36

tsconfig-up

TypeScript
1
star
37

tm-language-utils

textmate language convert utils
JavaScript
1
star
38

vscode-gtd

TypeScript
1
star
39

webpack4-taste

JavaScript
1
star
40

webpack-multi-entries

JavaScript
1
star
41

yo-ts-egg

a generator project for ts egg using yeoman
TypeScript
1
star
42

offline-iconfont

download fonts from iconfont.cn
JavaScript
1
star
43

vagusX-profile

vagusX's stats
1
star
44

icons-v4-diff

1
star
45

vscode-nbnhhsh

TypeScript
1
star
46

spring-boot-with-lombok

repo to reproduce java with lombok issue when renaming file and triggering refactoring changes
Java
1
star
47

test-project-1

1
star
48

non-js-import

path completion for non-js import in typescript & vscode
TypeScript
1
star
49

requill

A react rich text editor base on Quill
JavaScript
1
star
50

vagusX.github.io

personal website
CSS
1
star
51

git-petty-thing

petty thing about git
1
star
52

wepress

1
star
53

vue-tiny-mce

TinyMCE editor in vue
JavaScript
1
star
54

test-gh-action-cpus

JavaScript
1
star