Giter Club home page Giter Club logo

oneproxy's Introduction

OneProxy

OneProxy is a typical HTTP proxy + an interface to:

  1. Inject data (JS, HTML or Raw Data)
  2. Respond with data without making a request to the source server

Configuration:

Sample meta config:

{
    "app": {
        "PROXY_HOST": "127.0.0.1",
        "PROXY_PORT": "80",
        "SERVER_PORT": 5050
    },
    "interceptors": []
}
  • app.PROXY_HOST - The source server host
  • app.PROXY_PORT - The source server port
  • app.SERVER_PORT - Port on which oneproxy server runs
  • Interceptors - Array of interceptor config

Sample interceptor config: (Which is used in the demo)

[{
    "url": "/injectScript",
    "inject": true,
    "script": "alert('Script injected from config.json');"
}, {
    "url": "/injectScriptFromFile",
    "inject": true,
    "file": "./demo/files/injectJSFromFile.js"
}, {
    "url": "/injectRaw",
    "inject": true,
    "raw": true,
    "data": "<h1>This is injected from config.json</h1>"
}, {
    "url": "/injectRawFile",
    "inject": true,
    "raw": true,
    "file": "./demo/files/injectRawFile.html"
}, {
    "url": "/interceptRequest",
    "replace": true,
    "data": "Request has been intercepted, this is the response from config.json"
}, {
    "url": "/interceptRequestFromFile",
    "replace": true,
    "file": "./demo/files/interceptRequest.txt"
}]
  • URL - Path of the request to be matched by oneproxy
  • Inject (or) Replace
    • Inject - Inject the data or file to the response sent from source server, by default oneproxy considers this to be a JavaScript, hence data or the file is wrapped into a script tag and then injected to the HTML from the source server. However, you can set raw: true to ignore the script tag and inject the data as is
    • Replace - Respond to the request without calling the source server for the data, supports both data and file property

Let's get started using demo:

Clone oneproxy:

git clone https://github.com/codehate/oneproxy.git
cd oneproxy
npm install

Run demo server:

node demo/server.js

Server will be running at: http://127.0.0.1:3000

Start oneproxy:

# Use demo's config.json
node app.js --config=demo/config.json

Demo server is a simple server which returns the requested path:

For: http://127.0.0.1:3000

For: http://127.0.0.1:3000/path

Oneproxy in action:

Typical HTTP proxy: http://127.0.0.1:5050, this will send request to source server and proxy the response back:

Inject script:

http://127.0.0.1:5050/injectScript

Inject script from file:

http://127.0.0.1:5050/injectScriptFromFile

Inject raw content:

http://127.0.0.1:5050/injectRaw

Inject raw content from file:

http://127.0.0.1:5050/injectRawFile

Intercept the request:

http://127.0.0.1:5050/interceptRequest

Intercept the request from file:

http://127.0.0.1:5050/interceptRequestFromFile

oneproxy's People

Contributors

anands avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jakuta-tech

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.