Fastify
The API server preset using Fastify comes pre-configured to simplify development. Here's what you need to know to get started:
Knowledge of the Fastify framework is essential for optimal use. Read the documentation: https://fastify.dev/
Starting the Server
The file containing the code to start the server is located in src/server/index.ts
. The server will only start after the bot is ready! Therefore, a ready
event from the bot is used to start the server. See:
src/server/index.ts
This way, just import this file in src/index.ts
and the event will be recorded:
src/index.ts
Then the fastify server will start right after the bot goes online, thus having Client<true>
(Client instance when it is already online) to be used in the routes.
Environment Variables
The Zod schema for environment validation is adjusted to allow new environment variables:
src/env.ts
This means you can change the port of the Fastify server by setting this variable in the .env
file.
.env
Cors
In this preset, the cors plugin is already installed and has a basic configuration:
src/server/index.ts
Read the full plugin documentation to understand the best use cases: https://github.com/fastify/fastify-cors