@pybot/fastify-autoload
v0.2.0
Published
Fastify plugin for creating dynamic routes based on valid JSON
Downloads
6
Maintainers
Readme
@pybot/fastify-autoload
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