Coder Social home page Coder Social logo

Adding pre from request object about laabr HOT 6 CLOSED

felixheck avatar felixheck commented on September 6, 2024
Adding pre from request object

from laabr.

Comments (6)

felixheck avatar felixheck commented on September 6, 2024

Hi @JSteunou — thanks for opening this issue, really appreciating it 👍

That's true, req.pre is not included in laabr's req object and that's simply because it's not in hapi-pino's req object. So let me create a PR for hapi-pino. After it's merged, I'll release a minor update where you get access to pre within the request/response templates, like

{ awesomePreHandler: pre[key] }

Does this work for you?
Thanks a lot for your feedback.

from laabr.

felixheck avatar felixheck commented on September 6, 2024

But TBH: I'm not sure if it will be merged since it's a massive workaround on hapi-pino side

from laabr.

JSteunou avatar JSteunou commented on September 6, 2024

Yep I did dig a little and found out it was directly related to pino & hapi-pino serializer :(

I worked around it by adding another preHandler at the end of all my preHandlers that does nothing more than request.log and using some :message[field=msg] but I am not very proud of it because it adds a specific line of log instead of adding more data into request / response log.

from laabr.

felixheck avatar felixheck commented on September 6, 2024

Related: hapijs/hapi-pino#73

from laabr.

felixheck avatar felixheck commented on September 6, 2024

Hmm..I'm currently struggling with explaining a good use case.
I mean the responses of such prehandlers are like a payload and you wouldn't expect to print the payload automatically, right?

I would use a request.log(['info', 'pre'], somestuff) tbh.
Can you explain your use case in detail?

from laabr.

JSteunou avatar JSteunou commented on September 6, 2024

For example loading user / profile info in a preHandler, making request.pre.profile available for every handlers, and logging profile.id for some request / endpoint to help debug / trace.

from laabr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.