No description, website, or topics provided.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENCE
Makefile
README.md
index.js
package.json
x.js

README.md

stream-middleware

Streams as middleware

Example

var streams = require("stream-middleware")
    , partial = require("ap").partial
    , path = require("path")
    , through = require("through-stream")
    , from = require("read-stream")
    , filed = require("filed")
    , request = require("request")
    , http = require("http")

var app = streams()
    .route("/static/*", partial(filed, path.join(__dirname, "static")))

    .route("/proxypass", function (req) {
        return request("http://otherserver.com" + req.url)
    })

    .route("/hello.json"
        , partial(from, [{ msg: "hello" }])
        , partial(through, function (chunk, buffer) {
            buffer.push(JSON.stringify(chunk))
        })
        , header("content-type", "text/html"))

    .route("/plaintext"
        , partial(from, ["I like text/plain"])
        , header("content-type", "text/html"))

    .route("/")
        .method("GET"
            , partial(request, "http://me.iriscouch.com/db", {
                json: true
            })
            , partial(through, function (chunk, buffer) {
                buffer.push("<html><head>cool</head><body>" + chunk.index +
                    "</body></html>")
            })
            , header("content-type", "text/html"))
    ;

http.createServer(app, 3000)

function header(key, value) {
    return function (req, res) {
        return through(through.write, function () {
            res.setHeader(key, value)
        })
    }
}

function call(f) {
    return function() {
        f()
    }
}

Installation

npm install stream-middleware

Contributors

  • Raynos

MIT Licenced