fastify / fastify/fastify-nextjs

Fastify inject method instead of fetch or axios

Open
#721 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
558
Forks
62
Avg merge
2d 4h
Merged PRs (30d)
6

Description

### Prerequisites

- [X] I have written a descriptive issue title
- [X] 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.