Skip to content

bimedia-fr/architect-fastify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

architect-fastify

Expose Fastify server rest as an Architect plugin.

Installation

npm install --save architect-fastify

Config Format

{
  packagePath: 'architect-fastify',
  interface: process.env.IFACE, // Or host: process.env.IP
  port: process.env.PORT,
  server: { /* Fastify server option here */ },
  // optionnal pluggins
  plugins: {
    @fastify/middie: {
      hook: onRequest
    }
  }
}

Usage

Boot Architect:

const path = require('path');
const architect = require('architect');

const configPath = path.join(__dirname, 'config.js');
const config = architect.loadConfig(configPath);

architect.createApp(config, (err, app) => {
    if (err) {
        throw err;
    }
    console.log('App ready');
});

Configure Architect with config.js:

module.exports = [{
    packagePath: 'architect-fastify',
    port: process.env.PORT,
    host: process.env.IP
}, './routes'];

And register your routes in ./routes/index.js:

module.exports = function setup(options, imports, register) {
    const rest = imports.rest;

    // Register routes
    rest.get('/catalogue', async (req, reply) => {
        reply.send({ message: 'Hello, world' });
    });

    register();
};

// Consume rest plugin
module.exports.consumes = ['rest'];

Options

  • port: TCP port to listen to.
  • host: Host to listen to.
  • socket: Unix socket to listen to.
  • interface: Network interface name to listen to (must match os.networkInterfaces).
  • plugins: A hash containing either a Fastify plugin or a function that returns a plugin.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors