36 lines
773 B
JavaScript
36 lines
773 B
JavaScript
|
|
import Fastify from 'fastify';
|
||
|
|
import fastifyCors from '@fastify/cors';
|
||
|
|
import config from './config/index.js';
|
||
|
|
import dbPlugin from './plugins/db.js';
|
||
|
|
import routes from './routes/index.js';
|
||
|
|
|
||
|
|
export async function buildApp(opts = {}) {
|
||
|
|
const fastify = Fastify({
|
||
|
|
logger: {
|
||
|
|
level: opts.logLevel || 'info',
|
||
|
|
},
|
||
|
|
...opts,
|
||
|
|
});
|
||
|
|
|
||
|
|
// config 데코레이터 등록
|
||
|
|
fastify.decorate('config', config);
|
||
|
|
|
||
|
|
// CORS
|
||
|
|
await fastify.register(fastifyCors, {
|
||
|
|
origin: true,
|
||
|
|
});
|
||
|
|
|
||
|
|
// 플러그인
|
||
|
|
await fastify.register(dbPlugin);
|
||
|
|
|
||
|
|
// 라우트
|
||
|
|
await fastify.register(routes, { prefix: '/api' });
|
||
|
|
|
||
|
|
// 헬스 체크
|
||
|
|
fastify.get('/api/health', async () => {
|
||
|
|
return { status: 'ok', timestamp: new Date().toISOString() };
|
||
|
|
});
|
||
|
|
|
||
|
|
return fastify;
|
||
|
|
}
|