Skip to content

Fastify inject method instead of fetch or axios  #721

Open
@officefish

Description

@officefish

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

May be there is some way to accept fastify instance to NextRequest, then got it from getServerSideProps context, save it on page params and then use fastify.inject instead of fetch or axios?

I suppose it should be faster than ku_universal, axois and other libraries calls, but do not exactly understand how to pass fastify instance in render function.

I have an idea to extends RawRequest interface like

declare module 'fastify' {
    interface RawRequest {
        server: FastifyInstance
    }
} 

then give instance in gccp objects requests like :

 server.next(`/log-in`, async (app:NextServer, req:FastifyRequest, reply:FastifyReply) => {   
        // here we potentialy can accept fastify instance to req.raw
        raw.req.server = server
        await app.render(req.raw, reply.raw, '/log-in')
        reply.hijack()
})

and finally got ot from props

export const getServerSideProps: GetServerSideProps = async (context) => {
  const data = {server: context.req.server}
  return { props: { data } }
}

But unfortunatly there is no RawRequest interface in Fastify types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions