OneProxy is a typical HTTP proxy + an interface to:
- Inject data (JS, HTML or Raw Data)
- Respond with data without making a request to the source server
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
andfile
property
- 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
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/path
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: