69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import fastify from 'fastify';
|
|
import fastifyAutoload from '@fastify/autoload';
|
|
import { PrismaClient } from '@prisma/client';
|
|
// import { createClient, RedisClientType } from 'redis';
|
|
// import fastifySchedule from '@fastify/schedule';
|
|
// import fastifyCors from '@fastify/cors';
|
|
|
|
import path from 'path';
|
|
|
|
declare module 'fastify' {
|
|
interface FastifyInstance {
|
|
db: PrismaClient;
|
|
// redis: RedisClientType;
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
namespace NodeJS {
|
|
interface ProcessEnv {
|
|
NODE_ENV: 'development' | 'production';
|
|
PORT: number;
|
|
JWT_REFRESH_SECRET: string;
|
|
JWT_ACCESS_SECRET: string;
|
|
AUTH_CLIENT_ID: string;
|
|
AUTH_CLIENT_SECRET: string;
|
|
REDIS_URL: string;
|
|
URL_TOKEN: string;
|
|
}
|
|
}
|
|
}
|
|
|
|
fastify({
|
|
logger: true,
|
|
ajv: { customOptions: { allErrors: true } }
|
|
})
|
|
.decorate('db', new PrismaClient())
|
|
// .decorate('redis', async () => {
|
|
// const client = createClient({
|
|
// url: process.env.REDIS_URL
|
|
// });
|
|
|
|
// client.on('error', err => console.log('Redis Client Error', err));
|
|
|
|
// await client.connect();
|
|
// return client;
|
|
// })
|
|
.addHook('onRoute', route => console.log(route.url))
|
|
// .register(fastifyCors, {
|
|
// origin: ['http://127.0.0.1:3000'],
|
|
// credentials: true
|
|
// })
|
|
.register(fastifyAutoload, {
|
|
dir: path.join(__dirname, 'routes'),
|
|
routeParams: true,
|
|
autoHooks: true,
|
|
options: { prefix: '/api' }
|
|
})
|
|
.register(fastifyAutoload, {
|
|
dir: path.join(__dirname, 'link'),
|
|
routeParams: true,
|
|
autoHooks: true,
|
|
options: { prefix: '/a' }
|
|
})
|
|
.listen({ port: process.env.PORT || 8080, host: '0.0.0.0' })
|
|
// eslint-disable-next-line no-console
|
|
.then(() => console.log('Server Started'))
|
|
// eslint-disable-next-line no-console
|
|
.catch(console.error);
|