brandones
brandones

Reputation: 1947

morgan skip not working

Building an express app with morgan 1.9.0 and browser-refresh 1.7.2.

Morgan seems to be ignoring the skip option. My app is initialized with

const skipFcn = (req, res) => req.path.startsWith('/static/views')
app.use((req, res, next) => {
  console.log('test:', skipFcn(req, res))
  next()
})
app.use(morgan('combined', {
  skip: skipFcn
}))

But in my logs I'm still getting hundreds of hits from browser-refresh:

test: true
::1 - - [14/Oct/2017:10:09:07 +0000] "GET /static/views/project$0.0.0/views/components/service-form.marko.jsHTTP/1.1" 200 3748 "http://localhost:4002/admin/services" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"

Upvotes: 1

Views: 3951

Answers (2)

Luke Bayes
Luke Bayes

Reputation: 3284

Just checking in here.

I've been having the same problem. I couldn't figure out what I was doing wrong, and after far longer than it should have been, I went into node_modules/morgan/index.js and on line 80, added the following:

console.log('SKIP FUNCTION:', skip.toString());

This immediately showed the secret location in my project where I was also configuring Morgan, which was clobbering the new place where I was trying to configure Morgan (again).

After deleting my legacy configuration, morgan skip function started working beautifully.

Upvotes: 0

Andrew.Wolphoe
Andrew.Wolphoe

Reputation: 430

I use the following code and it worked

app.use(morgan('combined', {skip: (req, res) => {return req.originalUrl.startsWith('/src')}));

You probably want to try it and see if it works on your end.

Upvotes: 6

Related Questions