Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"csurf": "^1.2.2",
"dataloader": "^2.2.3",
"express": "^5.2.1",
"express-openapi-validator": "^5.3.9",
"express-session": "^1.19.0",
"fast-xml-parser": "^5.2.5",
"fluent-ffmpeg": "^2.1.3",
Expand Down
6 changes: 5 additions & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class AppController {
},
})
getStatus() {
return { message: 'TeachLink API is running', timestamp: new Date().toISOString() };
return {
success: true,
message: 'TeachLink API is running',
data: { timestamp: new Date().toISOString() },
};
}
}
41 changes: 41 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { RedisStore } from 'connect-redis';
import Redis from 'ioredis';

import { AppModule } from './app.module';
import * as OpenApiValidator from 'express-openapi-validator';
import { join } from 'path';
import './tracing/opentelemetry';

import { CorrelationIdMiddleware } from './middleware/correlation-id';
Expand Down Expand Up @@ -311,6 +313,45 @@ async function bootstrapWorker(): Promise<void> {
// =========================
app.useGlobalInterceptors(new LocaleInterceptor(), new PaginationInterceptor());

// =========================
// OPENAPI VALIDATION
// =========================
const apiSpecPath = join(process.cwd(), 'docs/api/openapi-spec.json');
app.use(
OpenApiValidator.middleware({
apiSpec: apiSpecPath,
validateRequests: true,
validateResponses: process.env.NODE_ENV !== 'production',
ignorePaths: /.*\/api\/docs.*/, // ignore swagger docs
}),
);

app.use((err: any, req: Request, res: Response, next: NextFunction) => {
if (err.status === 400 && err.errors) {
return res.status(400).json({
success: false,
message: 'Validation failed',
errors: err.errors.map((e: any) => ({
field: e.path,
message: e.message,
})),
});
}
if (
err.status === 500 &&
err.errors &&
typeof err.message === 'string' &&
err.message.toLowerCase().includes('response')
) {
logger.warn(`Response validation deviation: ${JSON.stringify(err.errors)}`);
return res.status(500).json({
success: false,
message: 'Internal server error',
});
}
next(err);
});

// =========================
// SWAGGER
// =========================
Expand Down
2 changes: 1 addition & 1 deletion src/workers/base/base.worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger, Inject } from '@nestjs/common';
import { Logger } from '@nestjs/common';
import { Job } from 'bull';
import Redis from 'ioredis';
import { getSharedRedisClient } from '../../config/cache.config';
Expand Down
2 changes: 1 addition & 1 deletion src/workers/orchestration/worker-orchestration.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Logger, OnModuleInit, OnModuleDestroy, Inject } from '@nestjs/common';
import { Injectable, Logger, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Job } from 'bull';
import { BaseWorker } from '../base/base.worker';
Expand Down
Loading