29 lines
679 B
TypeScript
29 lines
679 B
TypeScript
import Fastify from 'fastify';
|
|
import mercurius from 'mercurius';
|
|
|
|
import { config } from './config.js';
|
|
import { prisma } from './prisma.js';
|
|
import { resolvers, schema } from './graphql/schema.js';
|
|
|
|
const app = Fastify({ logger: true });
|
|
|
|
app.register(mercurius, {
|
|
schema,
|
|
resolvers,
|
|
graphiql: true,
|
|
context: async (request) => {
|
|
const header = request.headers['x-telegram-init-data'];
|
|
return {
|
|
telegramInitData: Array.isArray(header) ? header[0] : header,
|
|
};
|
|
},
|
|
});
|
|
|
|
app.get('/health', async () => ({ ok: true }));
|
|
|
|
app.addHook('onClose', async () => {
|
|
await prisma.$disconnect();
|
|
});
|
|
|
|
await app.listen({ host: config.host, port: config.port });
|