Files
pos-system/services/_template_nodejs/src/routes/index.ts
Ho Ngoc Hai 4e595d0746 feat(docs): Remove outdated service templates and enhance Vietnamese architecture documentation
- Deleted obsolete service architecture templates in both English and Vietnamese to streamline content.
- Updated the Vietnamese architecture documentation with improved Mermaid diagrams for better visual clarity.
- Enhanced color coding in diagrams to improve readability and consistency across documentation.
- Added a new section detailing visual indicators for better understanding of architecture components.
2026-01-10 21:00:02 +07:00

142 lines
4.3 KiB
TypeScript

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';
export const createRouter = (): Router => {
const router = Router();
const healthController = new HealthController();
const apiVersion = process.env.API_VERSION || 'v1';
// EN: Health check endpoints
// VI: Endpoints kiểm tra sức khỏe
/**
* @swagger
* /health:
* get:
* summary: Basic liveness probe
* description: Returns basic health status for liveness probes
* tags: [Health]
* responses:
* 200:
* description: Service is healthy
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/HealthResponse'
*/
router.get('/health', healthController.health);
/**
* @swagger
* /health/ready:
* get:
* summary: Readiness probe
* description: Checks if service is ready to handle requests (includes database connectivity)
* tags: [Health]
* responses:
* 200:
* description: Service is ready
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ReadinessResponse'
* 503:
* description: Service is not ready
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
router.get('/health/ready', healthController.ready);
/**
* @swagger
* /health/live:
* get:
* summary: Liveness probe
* description: Basic liveness check for container orchestration
* tags: [Health]
* responses:
* 200:
* description: Service is alive
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/LivenessResponse'
*/
router.get('/health/live', healthController.live);
// EN: Authentication demo endpoint
// VI: Endpoint demo xác thực
/**
* @swagger
* /auth/me:
* get:
* summary: Get current user information
* description: Returns information about the currently authenticated user
* tags: [Authentication]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: User information retrieved successfully
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/UserInfo'
* 401:
* description: Authentication required
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
router.get('/auth/me', authenticate(), (req, res) => {
const response: ApiResponse = {
success: true,
data: req.user,
message: 'User information retrieved / Thông tin người dùng đã được lấy',
timestamp: new Date().toISOString(),
};
res.json(response);
});
// API routes
router.use(`/api/${apiVersion}/features`, createFeatureRouter());
// EN: Metrics endpoint
// VI: Endpoint metrics
/**
* @swagger
* /metrics:
* get:
* summary: Get Prometheus metrics
* description: Returns application metrics in Prometheus format for monitoring
* tags: [Monitoring]
* responses:
* 200:
* description: Metrics in Prometheus format
* content:
* text/plain:
* schema:
* type: string
* example: "# HELP http_requests_total Total number of HTTP requests\n# TYPE http_requests_total counter\nhttp_requests_total{method=\"GET\",route=\"/health\",status=\"200\"} 42"
*/
const metricsController = new MetricsController();
router.get('/metrics', metricsController.getMetrics);
return router;
};