Coder Social home page Coder Social logo

koa-proxy's Introduction

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.

koa-proxy's People

Contributors

andreasrs avatar capaj avatar chrisveness avatar greengremlin avatar greim avatar kevinmook avatar lizell avatar mehiel avatar popomore avatar sdd avatar tomaash avatar yugloocamai avatar

Watchers

 avatar  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.