Added Documents Feature
This commit is contained in:
@@ -5,17 +5,20 @@
|
||||
import Fastify, { FastifyInstance } from 'fastify';
|
||||
import cors from '@fastify/cors';
|
||||
import helmet from '@fastify/helmet';
|
||||
import fastifyMultipart from '@fastify/multipart';
|
||||
|
||||
// Core plugins
|
||||
import authPlugin from './core/plugins/auth.plugin';
|
||||
import loggingPlugin from './core/plugins/logging.plugin';
|
||||
import errorPlugin from './core/plugins/error.plugin';
|
||||
import { appConfig } from './core/config/config-loader';
|
||||
|
||||
// Fastify feature routes
|
||||
import { vehiclesRoutes } from './features/vehicles/api/vehicles.routes';
|
||||
import { fuelLogsRoutes } from './features/fuel-logs/api/fuel-logs.routes';
|
||||
import { stationsRoutes } from './features/stations/api/stations.routes';
|
||||
import tenantManagementRoutes from './features/tenant-management/index';
|
||||
import { documentsRoutes } from './features/documents/api/documents.routes';
|
||||
|
||||
async function buildApp(): Promise<FastifyInstance> {
|
||||
const app = Fastify({
|
||||
@@ -27,6 +30,36 @@ async function buildApp(): Promise<FastifyInstance> {
|
||||
await app.register(cors);
|
||||
await app.register(loggingPlugin);
|
||||
await app.register(errorPlugin);
|
||||
|
||||
// Multipart upload support with config-driven size limits
|
||||
const parseSizeToBytes = (val: string): number => {
|
||||
// Accept forms like "10MB", "5M", "1048576", "20kb", case-insensitive
|
||||
const s = String(val).trim().toLowerCase();
|
||||
const match = s.match(/^(\d+)(b|kb|k|mb|m|gb|g)?$/i);
|
||||
if (!match) {
|
||||
// Fallback: try to parse integer bytes
|
||||
const n = parseInt(s, 10);
|
||||
return Number.isFinite(n) && n > 0 ? n : 10 * 1024 * 1024; // default 10MB
|
||||
}
|
||||
const num = parseInt(match[1], 10);
|
||||
const unit = match[2] || 'b';
|
||||
switch (unit) {
|
||||
case 'b': return num;
|
||||
case 'k':
|
||||
case 'kb': return num * 1024;
|
||||
case 'm':
|
||||
case 'mb': return num * 1024 * 1024;
|
||||
case 'g':
|
||||
case 'gb': return num * 1024 * 1024 * 1024;
|
||||
default: return num;
|
||||
}
|
||||
};
|
||||
const fileSizeLimit = parseSizeToBytes(appConfig.config.performance.max_request_size);
|
||||
await app.register(fastifyMultipart, {
|
||||
limits: {
|
||||
fileSize: fileSizeLimit,
|
||||
},
|
||||
});
|
||||
|
||||
// Authentication plugin
|
||||
await app.register(authPlugin);
|
||||
@@ -39,7 +72,17 @@ async function buildApp(): Promise<FastifyInstance> {
|
||||
status: 'healthy',
|
||||
timestamp: new Date().toISOString(),
|
||||
environment: process.env.NODE_ENV,
|
||||
features: ['vehicles', 'fuel-logs', 'stations', 'maintenance']
|
||||
features: ['vehicles', 'documents', 'fuel-logs', 'stations', 'maintenance']
|
||||
});
|
||||
});
|
||||
|
||||
// API-prefixed health for Traefik route validation and diagnostics
|
||||
app.get('/api/health', async (_request, reply) => {
|
||||
return reply.code(200).send({
|
||||
status: 'healthy',
|
||||
scope: 'api',
|
||||
timestamp: new Date().toISOString(),
|
||||
features: ['vehicles', 'documents', 'fuel-logs', 'stations', 'maintenance']
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,6 +110,7 @@ async function buildApp(): Promise<FastifyInstance> {
|
||||
|
||||
// Register Fastify feature routes
|
||||
await app.register(vehiclesRoutes, { prefix: '/api' });
|
||||
await app.register(documentsRoutes, { prefix: '/api' });
|
||||
await app.register(fuelLogsRoutes, { prefix: '/api' });
|
||||
await app.register(stationsRoutes, { prefix: '/api' });
|
||||
await app.register(tenantManagementRoutes);
|
||||
|
||||
Reference in New Issue
Block a user