fastify/fastify-http-proxy

TypeError: Cannot read properties of null (reading 'server')

renqian805 opened this issue · 2 comments

Prerequisites

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

Fastify version

4.27.0

Plugin version

9.5.0

Node.js version

18

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.5

Description

I throw an exception when I call handler(req, res):
minimal reproducible example
When the handler(req, res) is not called, everything is fine

Link to code that reproduces the bug

https://stackblitz.com/edit/vitejs-vite-3ehwyz?file=vite.config.ts

Expected Behavior

Expect normal operation

The link you included is a vite/vue app.
We often need a minimal reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

minimal reproducible example:

 const { createServer } = require('node:http')
 const Fastify = require('fastify');


 const httpServer = createServer()

 httpServer.listen({ port: 8085 });

 const server = Fastify({
    serverFactory: (handler) => {
        httpServer.on('request', (req, res) => {
            handler(req, res);
          });
          return httpServer;
    }
 });
 
 server.register(require('@fastify/http-proxy'), {
   upstream: 'http://my-api.example.com',
   prefix: '/api', // optional
   http2: false, // optional
 });