Re: Why is my middleware not called

502 views
Skip to first unread message

greelgorke

unread,
Nov 12, 2012, 3:10:42 AM11/12/12
to expre...@googlegroups.com
according to http://expressjs.com/api.html#app.use

"The order of which middleware are "defined" using app.use() is very important, they are invoked sequentially, thus this defines middleware precedence."

put your app.use middleware before the app.use router line, and it should work then.

Am Sonntag, 11. November 2012 01:31:25 UTC+1 schrieb Manuel Schoebel:
hey, i have a problem i did not have some versions of express.js ago (i think rc3).

i have the following simple code:

---------------
express = require("express")
app = express()

app.set "views", __dirname + "/views"
app.set "view engine", "jade"

app.configure ->
  app.use express.bodyParser()
  app.use express.cookieParser("secret")
  app.use express.cookieSession()
  app.use express.methodOverride()
  app.use app.router
  app.use express.static(__dirname + "/public")

getIndex = (req, res, next) ->
  console.log 'getIndex'
  res.render "sites/home/home2",
    title: "site"

# !!! This should be called on every request, but it does not !!!
app.use (req, res, next) ->
  console.log 'does not log'
  next()

app.get("/", getIndex)

app.listen process.env.PORT || 3000, ->
  console.log "Express server listening on port 3000 in %s mode", app.settings.env
---------------

I would expect that on every call to "/" the console would log 'does not log'. But it does not.

As i remember this worked not long ago. I would be very glad for any hints.

Thx

Manuel Schoebel

unread,
Nov 13, 2012, 5:03:33 AM11/13/12
to expre...@googlegroups.com
Yes, this makes sense. Thanks alot!
Reply all
Reply to author
Forward
0 new messages