How to use fastify-plugin - 3 common examples

To help you get started, we’ve selected a few fastify-plugin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HospitalRun / hospitalrun-server / test / helper.ts View on Github external
export const build = (t: any) => {
  const app = Fastify()

  // fastify-plugin ensures that all decorators
  // are exposed for testing purposes, this is
  // different from the production setup
  app.register(fp(App), config())

  // tear down our app after we are done
  t.tearDown(app.close.bind(app))

  return app
}
github google / node-fastify-auto-push / ts / src / index.ts View on Github external
reqPath &&
        // Record as a static file only when the path starts with `prefix`.
        reqPath.startsWith(prefix)
      ) {
        ap.recordRequestPath(resStream.session, reqPath, true);
      }
    }
  });
}

function noop() {}

// This type is probably not useful. Users probably want to call fp to
// instantiate the plugin specifically for their specific Http server, request
// and response types rather than using the union types like we do here.
export const staticServe = fp<
  HttpServer,
  RawRequest,
  RawResponse,
  AutoPushOptions
>(staticServeFn);
github SkeLLLa / fastify-metrics / src / index.ts View on Github external
});
        request.metrics.hist({
          method: method || 'UNKNOWN',
          route: routeId,
          status_code: statusCode,
        });
      }
      next();
    });
  }

  fastify.decorate(pluginName, plugin);
  next();
};

export = fastifyPlugin(fastifyMetricsPlugin, {
  fastify: '>=2.0.0',
  name: 'fastify-metrics',
});

fastify-plugin

Plugin helper for Fastify

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis

Popular fastify-plugin functions