Skip to content

Plugin encapsulation #2735

Closed Answered by jsumners
garretteklof asked this question in Q&A
Dec 11, 2020 · 4 comments · 7 replies
Discussion options

You must be logged in to vote

Fastify's encapsulation does not deal with any environment variables. The code you have provided is registering an asynchronous plugin without a callback. So it's rather surprising that it ever works. I imagine what you really want is:

const plugin = (fastify, opts, done) => {
  fastify.post("/", async function (request, reply) {
    const data = await getSomeData()
    return someSpecialCleaner(data)
  })

  done()
}

function someSpecialCleaner(data) {
  // do stuff
}

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
4 replies
@garretteklof
Comment options

@garretteklof
Comment options

@kibertoad
Comment options

@garretteklof
Comment options

Comment options

You must be logged in to vote
3 replies
@garretteklof
Comment options

@jsumners
Comment options

@garretteklof
Comment options

Answer selected by garretteklof
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants