Skip to content

Instantly share code, notes, and snippets.

@jfd
Created January 28, 2010 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfd/288729 to your computer and use it in GitHub Desktop.
Save jfd/288729 to your computer and use it in GitHub Desktop.
var pipe = require('pipe').pipe;
process.mixin(require('pipe/pipelets/all'));
//
// Creates a new http server running on port 8000. The server is started and
// piped immediately.
//
pipe ('http://127.0.0.1:8000') (
//
// Take the request object (in current pipe). Use the matching command to
// select the property called ´url´. Then, send it to the encoding pipelet
// called ´urlify´. The result is a URL-like object with properties of it's
// own.
//
urlify('url'),
//
// Select the `pathname` property of the Url object currently in pipe stream,
// then print it. This is for logging only, really.
//
format('Sending file %pathname ...'),
//
// Select the `pathname` and pass it to the out pipelet. The ´out´ pipelet
// opens a stream, based on url. In this case we are opening a local file
// with specified pathname. We are also telling `out` to send raise a
// HTTP_404 if an error occures while reading the stream.
//
out('file://.%pathname', { err: HTTP_404 })
);
var pipe = require('pipe').pipe;
var pipelets = require('pipelets');
var auth = require('auth_lib');
process.mixin(pipelets);
process.mixin(pipelets);
// Entry point for our application
pipe (tcp.createServer()) (
match (
//
// Match against all connect events.
//
{ type: 'connect' , data: String}, pipe (
// check authorization, drops the pipe if not authorized.
check_auth
),
//
// Match against all recive events.
//
{ type: 'recieve', data: String }, pipe (
// Convert json data to a object
json_parse('{data}'),
// Send data for processing to an other pipe process
pipe_forward('pipe://127.0.0.1:8000'),
// Take result from last origin and pass it to another pipe process
pipe_forward('pipe://127.0.0.1:8001'),
format('Sending result: %no back to tcp client..')
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment