mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 00:40:07 +00:00
* Migrate eslint and prettier to biomejs This does NOT include examples/bigbot as it has its own formatter * Update to biome 1.8.0 * Readd dotenv dev dependency to rest During a merge it got lost
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import fastifyEnv from '@fastify/env'
|
|
import fastifyHelmet from '@fastify/helmet'
|
|
import fastifyMultipart from '@fastify/multipart'
|
|
import fastify, { type FastifyInstance } from 'fastify'
|
|
|
|
export const buildFastifyApp = async (): Promise<FastifyInstance> => {
|
|
const app = await fastify()
|
|
|
|
await app.register(fastifyEnv, {
|
|
schema: {
|
|
type: 'object',
|
|
properties: {
|
|
HOST: {
|
|
type: 'string',
|
|
default: 'localhost',
|
|
},
|
|
DISCORD_TOKEN: {
|
|
type: 'string',
|
|
minLength: 1,
|
|
},
|
|
AUTHORIZATION_TOKEN: {
|
|
type: 'string',
|
|
minLength: 1,
|
|
},
|
|
},
|
|
required: ['DISCORD_TOKEN', 'AUTHORIZATION_TOKEN'],
|
|
},
|
|
})
|
|
|
|
await app.register(fastifyHelmet)
|
|
app.register(fastifyMultipart, { attachFieldsToBody: true })
|
|
|
|
app.addHook('onRequest', async (request, reply) => {
|
|
if (request.headers.authorization !== request.server.config.AUTHORIZATION_TOKEN) {
|
|
reply.status(401).send({
|
|
message: 'Credentials not valid.',
|
|
})
|
|
}
|
|
})
|
|
|
|
return app
|
|
}
|
|
|
|
declare module 'fastify' {
|
|
interface FastifyInstance {
|
|
config: {
|
|
HOST: string
|
|
DISCORD_TOKEN: string
|
|
AUTHORIZATION_TOKEN: string
|
|
}
|
|
}
|
|
}
|