• This repository has been archived on 24/Apr/2019
  • Stars
    star
    222
  • Rank 179,123 (Top 4 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated over 5 years ago

Reviews

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

Repository Details

Proxy middleware for koa

koa-proxy is been transfered to edorivai

koa-proxy Build Status Coverage Status

Proxy middleware for koa


Install

$ npm install koa-proxy -S

Usage

When you request http://localhost:3000/index.js, it will fetch http://alicdn.com/index.js and return.

var koa = require('koa');
var proxy = require('koa-proxy');
var app = koa();
app.use(proxy({
  host: 'http://alicdn.com'
}));
app.listen(3000);

You can proxy a specified url.

app.get('index.js', proxy({
  url: 'http://alicdn.com/index.js'
}));

You can specify a key/value object that can map your request's path to the other.

app.get('index.js', proxy({
  host: 'http://alicdn.com',
  map: {
    'index.js': 'index-1.js'
  }
}));

You can specify a function that can map your request's path to the desired destination.

app.get('index.js', proxy({
  host: 'http://alicdn.com',
  map: function(path) { return 'public/' + path; }
}));

You can specify match criteria to restrict proxy calls to a given path.

app.use(proxy({
  host:  'http://alicdn.com', // proxy alicdn.com...
  match: /^\/static\//        // ...just the /static folder
}));

Or you can use match to exclude a specific path.

app.use(proxy({
  host:  'http://alicdn.com',     // proxy alicdn.com...
  match: /^(?!\/dontproxy\.html)/ // ...everything except /dontproxy.html
}));

Proxy won't send cookie to real server, you can set jar = true to send it.

app.use(proxy({
  jar: true,
}));

Proxy won't send 'foo' and 'bar' headers to real server, or recieve 'jar-jar' from real server.

app.use(proxy({
  suppressRequestHeaders: ['foo','bar'], // case-insensitive
  suppressResponseHeaders: ['jar-jar'] // case-insensitive
}));

LICENSE

Copyright (c) 2014 popomore. Licensed under the MIT license.

More Repositories

1

projj

Manage repository easily.
JavaScript
260
star
2

github-labels

Add github labels automatically
JavaScript
177
star
3

jshint-practice

配置 jshint 的最佳实践
JavaScript
48
star
4

gulp-scp2

Copy file to remote server, using scp2 that is a pure javascript implement.
JavaScript
27
star
5

liquidluck-theme-reveal

liquidluck theme for reveal.js
Python
21
star
6

rename

Rename files using some transformers.
JavaScript
17
star
7

connect-combo

connect middleware for assets combo
JavaScript
16
star
8

projj-hooks

JavaScript
15
star
9

spy

spy and mock for simple testcase
JavaScript
14
star
10

ypkgfiles

Yet another pkgfiles that generate pkg.files automatically
JavaScript
13
star
11

social-share

A simple and easy-to-use social share tool.
JavaScript
13
star
12

gulp-mirror

Make a mirror of stream
JavaScript
12
star
13

checkurl

A tiny url status check tool
JavaScript
11
star
14

gulp-load

Load gulp task just like grunt.loadTasks.
JavaScript
11
star
15

schedule

A tiny cron-like tools for humman
JavaScript
10
star
16

chmod

chmod for nodejs
JavaScript
8
star
17

chuome

chuo.me Blog
JavaScript
8
star
18

decmdify

Transform CMD module to CommonJS
JavaScript
7
star
19

father

A package parser that can resolve self and dependencies, supporting spm, component.
JavaScript
7
star
20

gitx

Use git with custom identity file
JavaScript
6
star
21

puzzle

A puzzle game using aralejs
JavaScript
5
star
22

resolve-files

Get all files from the given entry that resolved by `require`
JavaScript
5
star
23

fzhidao

抓取百度知道的问题
Python
5
star
24

stream-switch

Stream condition for switch/case
JavaScript
4
star
25

findlinks

Find the broken links
JavaScript
4
star
26

nodejs-logo

Node.js logo
3
star
27

pan

Resolve pan.baidu.com download url
JavaScript
3
star
28

combo2

A simple assets combo server.
JavaScript
3
star
29

combo-url

resolve combo url
JavaScript
3
star
30

zhi

a key/value parser support simple template
JavaScript
3
star
31

test-id

2
star
32

exists-case

Wrap fs.exists for case sensitivity
JavaScript
2
star
33

puerh

a sinonjs assertion wrapper for expect
JavaScript
2
star
34

ibump

change version, create tag, publish to npm
JavaScript
1
star
35

foursquare-category

翻译 @4sq 的分类,帮助大家更好的选择和区分。
JavaScript
1
star
36

go-utils

1
star
37

istanbul-instrument

JavaScript
1
star
38

lrrrrc

Easy way to download lrc based on nodejs
JavaScript
1
star
39

gulp-switch

shim to stream-switch
Makefile
1
star
40

generator-popomore

my generator
JavaScript
1
star
41

nunjucks-vs-swig

JavaScript
1
star
42

configy

a configuration file parser
JavaScript
1
star
43

c8-mocha

JavaScript
1
star
44

fscache-stream

a passtrough stream caching buffer to file system
JavaScript
1
star
45

css-imports

find all @import in css
JavaScript
1
star
46

check-compiler

Makefile
1
star
47

css2str

transform css to string that can be inserted by js
JavaScript
1
star
48

cjsify

1
star
49

istanbul-example

istanbul example
JavaScript
1
star