Coder Social home page Coder Social logo

jdrew1303 / micro-proxy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dimapaloskin/micro-proxy

0.0 1.0 0.0 52 KB

Simplest proxy server for microservices

Home Page: https://zeit.co/blog/micro-proxy

License: MIT License

JavaScript 100.00%

micro-proxy's Introduction

micro-proxy

Build Status

With micro-proxy, you can create a proxy server for your microservices based on now.sh path alias rules.

This is specially well suited for development to mirror the production configuration of multiple microservices and backends.

Usage

Firstly, install the package:

npm i -g micro-proxy

Then add following rules to a filename called rules.json:

{
  "rules": [
    {"pathname": "/blog", "method":["GET", "POST", "OPTIONS"], "dest": "http://localhost:5000"},
    {"pathname": "/**", "dest": "http://localhost:4000"}
  ]
}

Visit path alias documentation to learn more about rules.

Run the proxy server with:

micro-proxy -r rules.json -p 9000

Now you can access the proxy via: http://localhost:9000

Programmatic Usage

You can run the proxy programmatically inside your codebase. For that, add micro-proxy to your project with:

npm install micro-proxy

Then create the proxy server like this:

const createProxy = require('micro-proxy')
const proxy = createProxy([
  {"pathname": "/blog", "method":["GET", "POST", "OPTIONS"], "dest": "http://localhost:5000"},
  {"pathname": "/**", "dest": "http://localhost:4000"}
])

proxy.listen(9000, (err) => {
  if (err) {
    throw err
  }
  console.log(`> Ready on http://localhost:9000`)
})

Production Usage

You can use micro-proxy as a production deployment.

But if you are using ZEIT now, you can simply use path alias rules instead.
(It's a FREE service available for all ZEIT now deployments.)

micro-proxy's People

Contributors

arunoda avatar dimapaloskin avatar leo avatar crisli avatar rauchg avatar kevinejohn avatar tomaswitek avatar

Watchers

James Drew 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.