fastify/help

fastify-express: fastify.use is not a function

vjustov opened this issue · 1 comments

💬 Question here

We recently migrated from registering everything in a server.js file to separating concerns with plugins. one plugin we are using to register a feature flags proxy.

Getting the following error when trying to use fastify-express as a plugin
TypeError: fastify.use is not a function

import fastifyExpress from "@fastify/express";
import { FastifyPluginAsync } from "fastify";
import { createApp } from "@unleash/proxy";

const featureFlagsProxy: FastifyPluginAsync = async (fastify) => {
  fastify.register(fastifyExpress).after(() => {
    const unleashProxy = createApp({
      unleashUrl: process.env.UNLEASH_INSTANCE_URL,
      unleashApiToken: "NOT_APPLICABLE",
      clientKeys: [process.env.UNLEASH_CLIENT_KEY as string],
      refreshInterval: 1000,
      unleashInstanceId: process.env.UNLEASH_INSTANCE_ID,
      unleashAppName: "dev",
    });
    
    fastify.use(unleashProxy);
  });
};

PD: The discord invite doesnt seem to be working, says invite invalid.

Your Environment

  • node version: v20.11.1
  • fastify version: 5.0.0
  • os: Mac 14.7

nvm, leaving a comment for prosperity, the after callback is only for error handling.