Skip to content

fix: resolve #265 - custom token named token breaks subsequent tokens#340

Open
abhii734 wants to merge 1 commit intoexpressjs:masterfrom
abhii734:master
Open

fix: resolve #265 - custom token named token breaks subsequent tokens#340
abhii734 wants to merge 1 commit intoexpressjs:masterfrom
abhii734:master

Conversation

@abhii734
Copy link

Bug (morgan#265)

Adding a token named "token" causes all subsequent tokens to break. This is because morgan.token() overwrites the morgan.token function itself.

Fix

  • Store custom tokens in separate tokenStore object
  • Prevent overwriting built-in properties (token, format, compile)
  • Add morgan.getToken() method for compiled format functions to lookup tokens
  • Also add NO_COLOR support in dev format (morgan#302)

Verification

Test code that previously failed:

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 : "") });

This now works without "TypeError: tokens.uuid is not a function"

…ng morgan

- Store custom tokens in separate tokenStore object
- Prevent overwriting built-in properties (token, format, compile)
- Add morgan.getToken() method to lookup tokens
- Also add NO_COLOR support in dev format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant