Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fastify: AvvioError [Error]: Plugin did not start in time

I’m currently working on a typescript/fastify project (which was a terrible stack choice imo). I’m getting this error while registering routes:

/home/20015007/Documents/Ecole/EcoWeb/econos-back/node_modules/avvio/plugin.js:122
      const err = new AVV_ERR_READY_TIMEOUT(name)
                  ^
AvvioError [Error]: Plugin did not start in time: 'declareHealthRoutes'. You may have forgotten to call 'done' function or to resolve a Promise
    at Timeout._onTimeout (/home/20015007/Documents/Ecole/EcoWeb/econos-back/node_modules/avvio/plugin.js:122:19)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7) {
  code: 'AVV_ERR_READY_TIMEOUT',
  fn: [Function: declareHealthRoutes]
}

Here is my code:

routes.ts:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import { declareArticleRoutes } from "./articlesRoutes";
import { declareContactRoutes } from "./contactRoutes";
import { declareAdminRoutes } from "./adminRoutes";
import { verifyJWT} from "../services/tokenService";
import { declareHealthRoutes } from "./healthRoutes";
function declareRoutes(fastify: FastifyInstance) {
    fastify.register(declareArticleRoutes);
    fastify.register(declareContactRoutes);
    fastify.register(declareHealthRoutes);
    fastify.register(declareAdminRoutes);
}

declareHealthRoute:

import {FastifyInstance, FastifyReply, FastifyRequest} from "fastify";

const healthSchema = {
    response: {
        200: {}
    }
};

function declareHealthRoutes(fastify: FastifyInstance): FastifyInstance {

    fastify.route({
        method: 'GET',
        url: '/health2',
        schema: healthSchema,
        handler: (req: FastifyRequest, reply: FastifyReply) => {
            return reply.status(200).send({});
        },
    });
    return fastify
}

export { declareHealthRoutes };

All of my routes are declared this simple way.

Just to say: I know how to get this code working (declareHealthRoutes(fastify) does register my route) but i’d like to understand why this is not working and if i’m not using the register the wrong way.

Any help is appreciated !

>Solution :

The function declareHealthRoutes must be async or call the callback:

async function declareHealthRoutes(fastify) { }

// or
function declareHealthRoutes(fastify, opts, next) {
  next()
}

otherwise, fastify does not know what the plugin is doing.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading