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

Ignoring specific HTTP endpoint (like health check endpoints) #119

Closed
hijklmno opened this issue Sep 2, 2016 · 4 comments
Closed

Ignoring specific HTTP endpoint (like health check endpoints) #119

hijklmno opened this issue Sep 2, 2016 · 4 comments
Assignees
Labels

Comments

@hijklmno
Copy link

hijklmno commented Sep 2, 2016

Hi,

Awesome middleware! Able to solve a handful of hard to pin down issues in production! Keep it up!

Right now I have a health check endpoint I defined as app.get('/health', handle). Is it possible to hide this from logs?

Thanks!

@dougwilson
Copy link
Contributor

You can either app.use this module after your health check route, or use the skip option to return true for that route (docs for skip option: https://github.com/expressjs/morgan#skip).

@hijklmno
Copy link
Author

hijklmno commented Sep 2, 2016

Skip works! Perfect! I implemented skip for that specific route via req.url with this code:

app.use(logger(config['morgan.debug.level'], {
    skip: function (req, res) {
        if (req.url == '/health') {
            return true;
        } else {
            return false;
        }
    }
}));

Thank you @dougwilson! Closing.

@hijklmno hijklmno closed this as completed Sep 2, 2016
@dougwilson dougwilson self-assigned this Sep 2, 2016
@dougwilson
Copy link
Contributor

No problem :)

@victorboissiere
Copy link

Great @hijklmno ! This is exactly what I needed!
I think you can simplify it:

app.use(logger(config['morgan.debug.level'], {
  skip: (req, res) => req.url === '/health'
}));

@expressjs expressjs locked as resolved and limited conversation to collaborators Apr 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants