Skip to content

kunal097/fastify-autoload

Repository files navigation

@pybot/fastify-autoload

Test workflow npm version NPM License

Fastify plugin for creating dynamic routes based on valid JSON.

Installation

npm i @pybot/fastify-autoload

Example

const fastify = require('fastify')
const autoload = require('@pybot/fastify-autoload')

const app = fastify({logger: true})

app.register(autoload, {
  dir: 'config'
})

app.listen({ port: 3000 })

Folder structure:

├── config
│   ├── api-server.json
│   ├── unsupported.txt
│   ├── trace.json
├── package.json
└── src
    └── index.js

Now we can specify multiple directories as well.

const fastify = require('fastify')
const autoload = require('@pybot/fastify-autoload')

const app = fastify({logger: true})

app.register(autoload, {
  dir: ['server-config', 'files']
})

app.listen({ port: 3000 })

Folder structure:

├── server-config
│   ├── api-server.json
│   ├── unsupported.txt
│   ├── trace.json
├── files
│   ├── invalid.json
│   ├── unsupported.txt
│   ├── server.json
├── package.json
└── src
    └── index.js

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published