Using Fastify Plugin
Vramework can be / is best used within fastify as a plugin.
Fastify plugin
import vrameworkFastifyPlugin from '@vramework/fastify-plugin'
import { createSingletonServices, createSessionServices } from 'path/to/vramework-bootstrap.ts'
// The fastify server setup goes here...
const singletonServices = await createSingletonServices()
app.register(vrameworkFastifyPlugin, {
vramework: {
singletonServices,
createSessionServices,
respondWith404: true,
logRoutes: true,
loadSchemas: true
}
})
Using VrameworkFastifyServer
note
The setup process for Express, uWS, and Fastify servers are identical, except for using different constructors.
VrameworkFastifyServer is a quick way to get a fastify server started with vramework if you don't need to put in any custom configuration.
Test
loading...
This script does the following:
- Imports necessary modules from
@vramework/fastify
and your project's configuration and services. - Defines an async function
runServer
that:- Loads the Vramework configuration
- Creates singleton services
- Initializes a new
VrameworkFastifyServer
instance - Enables graceful shutdown on SIGINT
- Initializes and starts the server
- Handles any errors by logging them and exiting the process
- Calls the
runServer
function to start the server
By following this setup, you can easily integrate Vramework with a Fastify server, benefiting from both Vramework's features and Fastify's performance.