chore: update gitignore for phase02

This commit is contained in:
hibna
2026-02-21 13:22:51 +03:00
parent 2215003a4d
commit 8eb7c90958
16 changed files with 479 additions and 29 deletions
+40 -3
View File
@@ -1,26 +1,63 @@
import Fastify from 'fastify';
import cors from '@fastify/cors';
import cookie from '@fastify/cookie';
import dbPlugin from './plugins/db.js';
import authPlugin from './plugins/auth.js';
import authRoutes from './routes/auth/index.js';
import { AppError } from './lib/errors.js';
const app = Fastify({
logger: {
transport: {
target: 'pino-pretty',
},
transport:
process.env.NODE_ENV !== 'production'
? { target: 'pino-pretty' }
: undefined,
},
});
// Plugins
await app.register(cors, {
origin: process.env.CORS_ORIGIN || 'http://localhost:5173',
credentials: true,
});
await app.register(cookie);
await app.register(dbPlugin);
await app.register(authPlugin);
// Error handler
app.setErrorHandler((error: Error & { validation?: unknown; statusCode?: number; code?: string }, _request, reply) => {
if (error instanceof AppError) {
return reply.code(error.statusCode).send({
error: error.name,
message: error.message,
code: error.code,
});
}
// Fastify validation errors
if (error.validation) {
return reply.code(400).send({
error: 'Validation Error',
message: error.message,
});
}
app.log.error(error);
return reply.code(500).send({
error: 'Internal Server Error',
message: 'An unexpected error occurred',
});
});
// Routes
app.get('/api/health', async () => {
return { status: 'ok', timestamp: new Date().toISOString() };
});
await app.register(authRoutes, { prefix: '/api/auth' });
// Start
const PORT = Number(process.env.PORT) || 3000;
const HOST = process.env.HOST || '0.0.0.0';