Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina
Author:Manuel Spigolon, Maksim Sinik & Matteo Collina [Manuel Spigolon, Maksim Sinik & Collina, Matteo]
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2023-05-15T00:00:00+00:00
These changes are breaking our setup due to the following reasons:
The config.js file is not loaded
The mongo-data-source.js file relies on fastify.secrets
To fix them, we need to edit app.js, as follows:
await fastify.register(require('./configs/config')) fastify.log.info('Config loaded %o', fastify.config)
These lines must be added after the autoload schemas configuration because we validate the environment variable through the schema:dotenv schema.
After that, we can update the pluginsâ autoload options as follows:
fastify.register(AutoLoad, { dir: path.join(__dirname, 'plugins'), dirNameRoutePrefix: false, ignorePattern: /.*.no-load\.js/, indexPattern: /^no$/I, options: fastify.config })
Finally, we can fix the mongo-data-source.js file by removing a lot of code:
module.exports = fp(async function (fastify, opts) { fastify.register(fastifyMongo, opts.mongo) })
As you can see, it has become much lighter. We have removed the dependencies parameter as well because we donât want to access the fastify.secret decorator.
This change has a significant impact on the code logic. With this code restyle, the mongo-data-source.js file is decoupled from the rest of the application because all the settings are provided by the input opts argument. This object is provided by the @fastify/autoload plugin, mapping the options parameter.
You now have a comprehensive and solid knowledge of the configuration and how to best manage it. You can use the previous code example to become confident in tweaking the plugins and playing within the autoload plugin. You will find that the source code in the bookâs repository adopts the first solution we saw in the Loading the pluginsâ configurations section.
To complete the project scaffolding, we need to add a few more features that are key pieces to consider this basic structure solid and ready to use for our development process. We will learn about some new plugins that add these missing capabilities to our application.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9864)
The Mikado Method by Ola Ellnestam Daniel Brolund(9744)
Dependency Injection in .NET by Mark Seemann(9290)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7742)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7513)
Svelte with Test-Driven Development by Daniel Irvine(6841)
Test-Driven Development with PHP 8 by Rainier Sarabia(6550)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6509)
Layered Design for Ruby on Rails Applications by Dementyev Vladimir;(6423)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6375)
Web Development with Django by Ben Shaw Saurabh Badhwar(5873)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5780)
React Application Architecture for Production by Alan Alickovic(5616)
Kotlin in Action by Dmitry Jemerov(5016)
Audition by Ryu Murakami(4552)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4294)
Software Architecture for Web Developers by Mihaela Roxana Ghidersa(4278)
Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina(4127)
Functional Programming in JavaScript by Mantyla Dan(4015)
