0.2.0 • Published 1 year ago
@pybot/fastify-autoload v0.2.0
@pybot/fastify-autoload
Fastify plugin for creating dynamic routes based on valid JSON.
Installation
npm i @pybot/fastify-autoloadExample
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.jsNow 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