0.8.6 • Published 6 years ago

fastify-plugin2 v0.8.6

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

fastify-plugin2

create support multi-instantiated fastify plugin.

Install

npm install fastify-plugin2 --save

API

fp2(decorateName, makeDecorate, pluginOptions);

fp2(decorateName, { decorate, routes }, pluginOptions);

Usage

const fastify = require('fastify')();
const fp2 = require('fastify-plugin2');

const rds = fp2('rds', (fastify, options, name) => {
  return {
    sayHello() {
      return `${name}: hello ${options.world}`;
    },
  };
});

fastify.register(rds, { name: 'db1', world: 'javascript' });
fastify.register(rds, { name: 'db2', world: 'fastify' });

fastify.get('/db1', async () => {
  return fastify.rds.db1.sayHello();
});

fastify.get('/db2', async () => {
  return fastify.rds.db2.sayHello();
});

fastify.listen(3000, function(err, address) {
  if (err) {
    fastify.log.error(err);
    process.exit(1);
  }
  fastify.log.info(`server listening on ${address}`);
});
0.8.6

6 years ago

0.8.5

6 years ago

0.8.2

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.6

6 years ago

0.6.0

6 years ago

0.5.5

6 years ago

0.5.0

6 years ago