morgan icon indicating copy to clipboard operation
morgan copied to clipboard

Support for promise

Open thethakuri opened this issue 2 years ago • 2 comments

I am writing a custom token with async callback method that looks up value in a database. Problem is http request is logged in as [object Promise] for the custom token and doesn't "await" for the value to be resolved. Is there a workaround for this?

thethakuri avatar Jan 22 '23 09:01 thethakuri

Hi @thethakuri right now all format functions and token functions are expected to be sync. We can add async support, however.

dougwilson avatar Feb 17 '23 21:02 dougwilson

Maybe you can do this:

morgan(
  (tokens, req, res) => {
    oneAsyncFunction(tokens, req, res)
    return null
  },
  { ... }
)

you can replace stream function.

qq1147050160 avatar Dec 01 '23 07:12 qq1147050160