1

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"
2
  • I tried your example myself and it seems to work for me. The only thing I can think of is that the log line is coming from somewhere else. Try commenting out the app.use(morgan(... bit to confirm it's the only logging in play here. If it isn't something simple like that I suggest attaching the Chrome debugger to your Node and stepping through.
    – skirtle
    Commented Oct 14, 2017 at 21:34
  • I also got the same issue Commented Feb 2, 2018 at 12:18

2 Answers 2

6

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.

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.