Argo
An extensible, asynchronous HTTP reverse proxy and origin server.
Examples
Adding Cross-Origin Resource Sharing
Setup the server:
var argo = ; target'http://weather.yahooapis.com' ;
Make a request:
$ curl -i http://localhost:1337/forecastrss?w=2467861 HTTP/1.1 200 OKDate: Thu, 28 Feb 2013 20:55:03 GMTContent-Type: text/xml;charset=UTF-8Connection: keep-aliveServer: YTS/1.20.13Access-Control-Allow-Origin: *Content-Length: 2337 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?><GiantXMLResponse/>
Serving an API Response
Setup the server:
var argo = ; ;
Make a request:
$ curl -i http://localhost:1337/dogs HTTP/1.1 200 OKContent-Type: application/jsonContent-Length: 34 Date: Thu, 28 Feb 2013 20:44:46 GMTConnection: keep-alive {"dogs":["Alfred","Rover","Dino"]}
Install
$ npm install argo
Documentation
- handleFunction
- use(handleFunction)
- use(package)
- target
- route
- Method filters
- map
- include
- listen
- Error Handling
Usage ### handleFunction(type, [options], callback)
-
type
:'request'
or'response'
-
options
: Mostly used for internal purposes. Optional. -
callback(env, next)
: A request or response callback.env
is an environment context that is passed to every handler, andnext
is a reference to the next function in the pipeline.
When the handler is complete and wishes to pass to the next function in the pipeline, it must call next(env)
.
handleFunction
is used to set up request and response handlers.
//For every request add 'X-Custom-Header' with value 'Yippee!'
Alias for include(package)
.
target
is used for proxying requests to a backend server.
uri
: a string pointing to the target URI.
Example:
target'http://weather.yahooapis.com'
-
path
: a regular expression used to match HTTP Request URI path. -
options
: an object with amethods
property to filter HTTP methods (e.g.,{ methods: ['GET','POST'] }
). Optional. -
handleFunction
: Same as inuse
.
Example:
Method filters #### get(path, handleFunction) #### post(path, handleFunction) #### put(path, handleFunction) #### head(path, handleFunction) #### del(path, handleFunction) #### options(path, handleFunction) #### trace(path, handleFunction) #### copy(path, handleFunction) #### lock(path, handleFunction) #### mkcol(path, handleFunction) #### move(path, handleFunction) #### propfind(path, handleFunction) #### proppatch(path, handleFunction) #### unlock(path, handleFunction) #### report(path, handleFunction) #### mkactivity(path, handleFunction) #### checkout(path, handleFunction) #### merge(path, handleFunction) #### msearch(path, handleFunction) #### notify(path, handleFunction) #### subscribe(path, handleFunction) #### unsubscribe(path, handleFunction) #### patch(path, handleFunction) #### search(path, handleFunction)
Method filters built on top of route
. del
and msearch
correspond to
the DELETE and M-SEARCH methods, respectively.
Example:
map
is used to delegate control to sub-Argo instances based on a request URI path.
-
path
: a regular expression used to match the HTTP Request URI path. -
options
: an object with amethods
property to filter HTTP methods (e.g.,{ methods: ['GET','POST'] }
). Optional. -
argoSegmentFunction
: a function that is passed an instance ofargo
for additional setup.
Example:
package
: An object that contains apackage
property.
The package
property is a function that takes an argo instance as a paramter and returns an object that contains a name
and an install
function.
Example:
var { return name: 'Super Package' { argo ; } ;};
port
: A port on which the server should listen.
Argo allows a special error
handler for capturing state when an uncaught exception occurs.
;
Unlike other named pipelines, there should be only one error handler assigned to an Argo server. It is recommended to exit the process once an error has been handled. This feature uses domains.
See cluster.js
for an example of using error handling to restart workers in a cluster.
Tests
Unit tests:
$ npm test
Test Coverage:
$ npm run-script coverage
License
MIT