add some features

This commit is contained in:
2026-04-22 21:37:07 +02:00
parent bdd06105dd
commit 52c3e68613
20 changed files with 2097 additions and 1030 deletions
+77
View File
@@ -3,6 +3,8 @@ import cors from 'cors';
import express from 'express';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import swaggerJsdoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
import { errorHandler, notFoundHandler } from './middleware/errorHandler.js';
import { requireAdminAuth, requireAnyAuth, requireUserAuth } from './middleware/authMiddleware.js';
@@ -16,6 +18,81 @@ import templateRoutes from './routes/templateRoutes.js';
const app = express();
// Trust reverse proxy headers to get real client IP address
app.set('trust proxy', true);
/*
* Swagger API documentation configuration.
*/
const swaggerOptions = {
definition: {
openapi: '3.0.0',
info: {
title: 'Check List PoC API',
version: '0.2.0',
description: 'Versioned PoC API for template, configuration, and report management.',
},
servers: [
{ url: '/', description: 'Local server' },
],
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
cookieAuth: {
type: 'apiKey',
in: 'cookie',
name: 'auth_token',
},
},
},
security: [{ bearerAuth: [] }, { cookieAuth: [] }],
tags: [
{ name: 'Admin' },
{ name: 'Admin: Categories' },
{ name: 'Admin: Sub Categories' },
{ name: 'Admin: Severities' },
{ name: 'Admin: Statuses' },
{ name: 'Admin: Handled By' },
{ name: 'Admin: Projects' },
{ name: 'Admin: Processes' },
{ name: 'Admin: Users' },
{ name: 'Admin: Sites' },
{ name: 'Admin: CL Records' },
{ name: 'Admin: CL Templates' },
{ name: 'Admin: Tasks' },
{ name: 'Configuration' },
{ name: 'Templates' },
{ name: 'Reports' },
{ name: 'Authentication' },
{ name: 'Health' },
],
},
apis: ['./src/routes/*.js'],
};
const swaggerSpec = swaggerJsdoc(swaggerOptions);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec, {
customCss: '.swagger-ui .topbar { display: none }',
customSiteTitle: 'Check List API Docs',
}));
/*
* Request logging middleware for all API endpoints.
*/
app.use('/api', (req, res, next) => {
const start = Date.now();
res.on('finish', () => {
const duration = Date.now() - start;
console.log(`${req.ip} ${req.method} ${req.originalUrl} ${res.statusCode} ${duration}ms`);
});
next();
});
/*
* The application serves two concerns from the same Express process:
* 1. a versioned REST API (v1) used by the proof-of-concept frontend,