montagejs / joey

An HTTP content negotiation client and server JavaScript library, inspired by Sinatra and JSGI, and using Q promises.
Other
40 stars 7 forks source link

readme example not working #1

Closed boxxxie closed 7 years ago

boxxxie commented 11 years ago

i edited the readme code to look like the below

require("joey").log().error().favicon().route(function($) {

    $("").method("GET").contentType("text/plain").content("Hello, World!")

    $("hello/:name").method("GET").contentType("text/html").contentApp(function(request) {
        return "Hello, " + request.params.name + "!\n";
    })

    $("store").methods(function($) {

        var content = "\n";

        $("GET").contentType("text/plain").contentApp(function() {
            return content;
        });

        $("PUT").tap(function(request) {
            return request.body.read().then(function(_content) {
                content = _content.toString("utf-8");
            });
        }).redirect("");

    })

    $("files/...").fileTree("."); // danger!
}).listen(8080).then(function() {
    console.log("Listening on 8080")

    // client
    var request = require("joey").cookieJar().redirectTrap(20).client();

    request("http://localhost:8080").then(function(response) {
        console.log(response.status, response.headers);
        response.body.read().invoke('toString', 'utf-8').then(console.log)
    })
}).done()

this line throws an error request("http://localhost:8080").then(function(response) {

the error thrown is:

/home/paul/eg/api/node_modules/q/q.js:1319
                throw error;
                      ^
TypeError: Cannot read property 'host' of undefined
    at exports.CookieJar (/home/paul/eg/api/node_modules/q-io/http-apps.js:1267:55)
    at /home/paul/eg/api/src/joey-app.js:42:2
From previous event:
    at Object.<anonymous> (/home/paul/eg/api/src/joey-app.js:36:17)
kriskowal commented 11 years ago

I’ll take a look and make a spec.

hthetiot commented 7 years ago

Fixed: