Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Each layer must have a route and a handle function" -- what is the "route" function? #49

Closed
jameshfisher opened this issue Jul 3, 2010 · 9 comments

Comments

@jameshfisher
Copy link

I'm confused as to what the "route" function is in a layer. I don't see it documented; what is its signature and what is it meant to do?

(Also, is the documentation at http://extjs.github.com/Connect/ tested? I see the following in the "Middleware" section:

module.exports = connect.createServer(
    connect.logger(),
    connect.static(__dirname + '/public)
);

which seems to have an invalid reference (static instead of staticProvider) and an unclosed string literal.)

@jameshfisher
Copy link
Author

All I see at connect/index.js (where the error originates) is

/**

  • Stack the given middleware handle to the given route.
    *
  • @param {String} route
  • @param {Function} handle
  • @return {Server}
  • @api public
    */

Ok, so "route" is a string, not a function. (That ambiguity in the error message should be eliminated.) But anyway, what does this mean? "Route" as in the "router" middleware? I can't see how that has anything to do with it, and I can't think of another relevant type of "route" this could be.

@tj
Copy link
Member

tj commented Jul 3, 2010

shit, year static() should be staticProvider(). I am not sure that "route" is the proper word to describe it, personally I would call it a "mount path" or something, but basically it allows you to "mount" say the static middleware to a specific base path, for example server.use("/public", connect.staticProvider())

@jameshfisher
Copy link
Author

... ok. I don't think I understand. Let's take the examples at http://howtonode.org/connect-it . Neither the "from scratch" app, nor the "robust using built-in" app, work: when I run connect server.js, I get

/home/lm/.node_libraries/connect/index.js:146
        throw new Error("Each layer must have a route and a handle function");

I get exactly the same if I set exports.route in serve-js.js and log-it.js, like so:

exports.route = __dirname;

So to keep this simple, how should the tutorial at the above URL be changed for it to now work?

@tj
Copy link
Member

tj commented Jul 5, 2010

that tutorial is pretty old now.. you can basically use the example above, with staticProvider instead of "static" (which I will fix), and run connect

@creationix
Copy link
Member

Perhaps I should update the article. Updating...

@frank06
Copy link

frank06 commented Jul 20, 2010

Many examples with latest connect and express don't work. "Each layer must have a route and a handle function" in all of them. Bug?

@tj
Copy link
Member

tj commented Jul 20, 2010

its because I made a change to allow server.use(fn) instead of server.use('/', fn) my examples use the former, which unfortunately will blow up right now, I should switch them until a new connect is released

@frank06
Copy link

frank06 commented Jul 20, 2010

if it's for me it's ok... given that you can pass those into express.createServer() without a path ... so no biggie. thanks

@tj
Copy link
Member

tj commented Jul 20, 2010

my and guillermo had a big talk about dependencies. its a stupid issue with node stuff right now. git IS a package manager essentially, we talked about vendorizing connect in express, but it leads to other problems so I dont have a good answer at this moment but the preferred install method would probably be $ curl http://expressjs.com/install.sh | sh

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants