refactor: Sắp xếp lại các import và đơn giản hóa khối catch trong health controller.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { z } from 'zod';
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
import { z } from 'zod';
|
||||
|
||||
// EN: Load environment variables (optional for local development without Docker)
|
||||
// VI: Tải biến môi trường (tùy chọn cho phát triển local không dùng Docker)
|
||||
// EN: In production, environment variables are set via Docker Compose or Kubernetes
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
/**
|
||||
* EN: Prisma client instance configured for the application
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Redis from 'ioredis';
|
||||
import { appConfig } from './app.config';
|
||||
import { logger } from '@goodgo/logger';
|
||||
import Redis from 'ioredis';
|
||||
|
||||
import { appConfig } from './app.config';
|
||||
|
||||
// EN: Redis connection instance
|
||||
// VI: Instance kết nối Redis
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Application } from 'express';
|
||||
import swaggerJSDoc from 'swagger-jsdoc';
|
||||
import swaggerUi from 'swagger-ui-express';
|
||||
import { Application } from 'express';
|
||||
|
||||
/**
|
||||
* EN: Swagger/OpenAPI configuration for API documentation
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import helmet from 'helmet';
|
||||
import rateLimit from 'express-rate-limit';
|
||||
import { RedisStore } from 'rate-limit-redis';
|
||||
import { connectDatabase } from './config/database.config';
|
||||
import { appConfig } from './config/app.config';
|
||||
import { getRedisClient } from './config/redis.config';
|
||||
import { createRouter } from './routes';
|
||||
import { requestLogger } from './middlewares/logger.middleware';
|
||||
import { errorHandler, notFoundHandler } from './middlewares/error.middleware';
|
||||
import { metricsMiddleware } from './middlewares/metrics.middleware';
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { initTracing } from '@goodgo/tracing';
|
||||
import cors from 'cors';
|
||||
import express from 'express';
|
||||
import rateLimit from 'express-rate-limit';
|
||||
import helmet from 'helmet';
|
||||
import { RedisStore } from 'rate-limit-redis';
|
||||
|
||||
import { appConfig } from './config/app.config';
|
||||
import { connectDatabase } from './config/database.config';
|
||||
import { prisma } from './config/database.config';
|
||||
import { getRedisClient } from './config/redis.config';
|
||||
import { setupSwagger } from './docs/swagger';
|
||||
import { correlationMiddleware } from './middlewares/correlation.middleware';
|
||||
import { errorHandler, notFoundHandler } from './middlewares/error.middleware';
|
||||
import { requestLogger } from './middlewares/logger.middleware';
|
||||
import { metricsMiddleware } from './middlewares/metrics.middleware';
|
||||
import { createRouter } from './routes';
|
||||
|
||||
// EN: Initialize tracing
|
||||
// VI: Khởi tạo tracing
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { verifyToken, extractTokenFromHeader } from '@goodgo/auth-sdk';
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { ApiResponse } from '@goodgo/types';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
|
||||
/**
|
||||
* EN: Extended Request interface with user information
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { randomUUID } from 'crypto';
|
||||
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
|
||||
/**
|
||||
* EN: Correlation ID header name
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import express from 'express';
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { HttpError } from '../errors/http-error';
|
||||
import express from 'express';
|
||||
|
||||
import { ErrorCode, getStatusFromErrorCode, isOperationalError } from '../errors/error-codes';
|
||||
import { HttpError } from '../errors/http-error';
|
||||
|
||||
/**
|
||||
* EN: Global error handler middleware with enhanced error handling
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
|
||||
import { getCorrelationId, getRequestId } from './correlation.middleware';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import client from 'prom-client';
|
||||
|
||||
import { getCorrelationId } from './correlation.middleware';
|
||||
|
||||
// EN: Create a Registry which registers the metrics
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { z, ZodError } from 'zod';
|
||||
import { logger } from '@goodgo/logger';
|
||||
|
||||
/**
|
||||
* EN: Middleware to validate request data using Zod schemas
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { getRedisClient } from '../../config/redis.config';
|
||||
import { logger } from '@goodgo/logger';
|
||||
|
||||
import { getRedisClient } from '../../config/redis.config';
|
||||
|
||||
/**
|
||||
* EN: Service for caching data (Redis wrapper)
|
||||
* VI: Service cho việc caching dữ liệu (Redis wrapper)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import CircuitBreaker from 'opossum';
|
||||
import { logger } from '@goodgo/logger';
|
||||
import CircuitBreaker from 'opossum';
|
||||
|
||||
/**
|
||||
* EN: Circuit Breaker Configuration
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
import { DatabaseError } from '../../errors/http-error';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { ApiResponse } from '@goodgo/types';
|
||||
import { FeatureService } from './feature.service';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
import { asyncHandler } from '../../middlewares/error.middleware';
|
||||
|
||||
import { FeatureService } from './feature.service';
|
||||
|
||||
|
||||
/**
|
||||
* EN: Controller for Feature module
|
||||
* VI: Controller cho module Feature
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Router } from 'express';
|
||||
import { FeatureController } from './feature.controller';
|
||||
|
||||
import { validateDto } from '../../middlewares/validation.middleware';
|
||||
|
||||
import { FeatureController } from './feature.controller';
|
||||
import { createFeatureDtoSchema, updateFeatureDtoSchema } from './feature.dto';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { prisma } from '../../config/database.config';
|
||||
import { BaseRepository, IRepository } from '../common/repository';
|
||||
import { ConflictError } from '../../errors/http-error';
|
||||
import { logger } from '@goodgo/logger';
|
||||
|
||||
import { prisma } from '../../config/database.config';
|
||||
import { ConflictError } from '../../errors/http-error';
|
||||
import { BaseRepository, IRepository } from '../common/repository';
|
||||
|
||||
// EN: Feature entity type from Prisma
|
||||
// VI: Feature entity type từ Prisma
|
||||
type Feature = {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { featureRepository } from './feature.repository';
|
||||
|
||||
import { NotFoundError } from '../../errors/http-error';
|
||||
|
||||
import { featureRepository } from './feature.repository';
|
||||
|
||||
/**
|
||||
* EN: Service for managing features in the system
|
||||
* VI: Service để quản lý các features trong hệ thống
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { prisma } from '../../config/database.config';
|
||||
import { ApiResponse } from '@goodgo/types';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
import { prisma } from '../../config/database.config';
|
||||
|
||||
/**
|
||||
* EN: Controller for health checks
|
||||
@@ -38,7 +39,7 @@ export class HealthController {
|
||||
data: { status: 'ready' },
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
} catch (error) {
|
||||
} catch {
|
||||
// EN: Return 503 if database is not ready
|
||||
// VI: Trả về 503 nếu database chưa sẵn sàng
|
||||
res.status(503).json({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { Request, Response } from 'express';
|
||||
import { register } from 'prom-client';
|
||||
import { logger } from '@goodgo/logger';
|
||||
|
||||
/**
|
||||
* EN: Controller for handling metrics requests
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { ApiResponse } from '@goodgo/types';
|
||||
import { Router } from 'express';
|
||||
|
||||
import { authenticate } from '../middlewares/auth.middleware';
|
||||
import { createFeatureRouter } from '../modules/feature/feature.module';
|
||||
import { HealthController } from '../modules/health/health.controller';
|
||||
import { MetricsController } from '../modules/metrics/metrics.controller';
|
||||
import { authenticate } from '../middlewares/auth.middleware';
|
||||
import { ApiResponse } from '@goodgo/types';
|
||||
|
||||
|
||||
export const createRouter = (): Router => {
|
||||
|
||||
Reference in New Issue
Block a user