expressjs / morgan

HTTP request logger middleware for node.js
MIT License
7.95k stars 536 forks source link

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

Open WadeDutch opened 2 years ago

WadeDutch commented 2 years ago

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 : "") });
dougwilson commented 2 years ago

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.

WadeDutch commented 2 years ago

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

dougwilson commented 2 years ago

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