morgan icon indicating copy to clipboard operation
morgan copied to clipboard

Adding a token named token causes all subsequent tokens to break.

Open WadeDutch opened this issue 3 years ago • 3 comments

This works just fine:

var logger = require('morgan');
logger.token('ip', function (req, res) { return req.ip ? req.ip : "" });
logger.token('uuid', function (req, res) { return (req.token ? req.token.uuid : "") });
logger.token('token', function (req, res) { return (req.token ? req.token.token : "") });

This gives "TypeError: tokens.uuid is not a function" when called in the logger:

var logger = require('morgan');
logger.token('ip', function (req, res) { return req.ip ? req.ip : "" });
logger.token('token', function (req, res) { return (req.token ? req.token.token : "") });
logger.token('uuid', function (req, res) { return (req.token ? req.token.uuid : "") });

WadeDutch avatar Jul 27 '22 20:07 WadeDutch

Ah yes, that is def a footgun. We should make it an error when trying to use a reserved word in 1.x line and also get a beta of 2.0 published which allows any token name and the other 2.0 stuff, haha.

dougwilson avatar Jul 27 '22 21:07 dougwilson

Figured as much. Is there a list of reserved words anywhere?

WadeDutch avatar Jul 27 '22 21:07 WadeDutch

Not currently, so that is another thing to add: docs for this :)

dougwilson avatar Jul 27 '22 21:07 dougwilson