This commit is contained in:
silverpro89
2026-01-19 20:32:23 +07:00
parent 70838a4bc1
commit 97e2e8402e
14 changed files with 10115 additions and 686 deletions

39
app.js
View File

@@ -5,6 +5,7 @@ const compression = require('compression');
const morgan = require('morgan');
require('express-async-errors'); // Handle async errors
const config = require('./config/config.json');
const { swaggerUi, swaggerSpec } = require('./config/swagger');
// Import configurations
const { initializeDatabase } = require('./config/database');
@@ -44,9 +45,9 @@ app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'"],
styleSrc: ["'self'", "'unsafe-inline'"],
imgSrc: ["'self'", "data:", "https:"],
scriptSrc: ["'self'", "'unsafe-inline'"], // Allow inline scripts for Swagger UI
styleSrc: ["'self'", "'unsafe-inline'"], // Allow inline styles for Swagger UI
imgSrc: ["'self'", "data:", "https:", "validator.swagger.io"], // Allow Swagger validator
connectSrc: ["'self'"],
fontSrc: ["'self'"],
objectSrc: ["'none'"],
@@ -125,8 +126,8 @@ app.get('/api', (req, res) => {
name: 'Sena School Management API',
version: '1.0.0',
description: 'API for managing 200 schools with Redis caching and BullMQ job processing',
enauth: '/api/auth',
dpoints: {
endpoints: {
auth: '/api/auth',
schools: '/api/schools',
classes: '/api/classes',
academicYears: '/api/academic-years',
@@ -143,10 +144,36 @@ app.get('/api', (req, res) => {
chapters: '/api/chapters',
games: '/api/games',
},
documentation: '/api/docs',
documentation: '/api-docs',
});
});
/**
* Swagger API Documentation
*/
app.use('/api-docs', swaggerUi.serve);
app.get('/api-docs', swaggerUi.setup(swaggerSpec, {
customCss: '.swagger-ui .topbar { display: none }',
customSiteTitle: 'SENA API Documentation',
customfavIcon: '/favicon.ico',
swaggerOptions: {
persistAuthorization: true,
displayRequestDuration: true,
filter: true,
syntaxHighlight: {
theme: 'monokai',
},
},
}));
/**
* Swagger JSON endpoint
*/
app.get('/api-docs.json', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
/**
* API Routes
*/