fastify-min/app.js

25 lines
709 B
JavaScript
Raw Normal View History

2024-11-09 14:10:29 +00:00
import AutoLoad from '@fastify/autoload'
import path from 'path';
import { dirname } from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
// Setting up the autoloader for plugins and routes.
export default async function (fastify, opts) {
// Require all the plugins that we'll need in our application.
await fastify.register(AutoLoad, {
dir: path.join(__dirname,'plugins'),
options: Object.assign({}, opts)
})
// Then, we'll load all of our routes.
await fastify.register(AutoLoad, {
dir: path.join(__dirname,'routes'),
dirNameRoutePrefix: false,
options: Object.assign({}, opts)
})
}