Add security and performance enhancements, remove unused code

Deleted unused spec files for app controller and service to clean up the codebase. Added helmet middleware for security and integrated ThrottlerModule for rate limiting and ConfigModule for configuration management. Updated app.service to modify response structure.
This commit is contained in:
Mathis H (Avnyr) 2024-09-02 14:58:28 +02:00
parent be121ef7ca
commit d4a224614e
No known key found for this signature in database
GPG Key ID: FF69BF8BF95CDD58
5 changed files with 28 additions and 56 deletions

View File

@ -1,22 +0,0 @@
import { Test, TestingModule } from "@nestjs/testing";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
describe("AppController", () => {
let app: TestingModule;
beforeAll(async () => {
app = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
});
describe("getData", () => {
it('should return "Hello API"', () => {
const appController = app.get<AppController>(AppController);
expect(appController.getData()).toEqual({ message: "Hello API" });
});
});
});

View File

@ -1,12 +1,29 @@
import { Module } from "@nestjs/common"; import { Module } from '@nestjs/common';
import { AppController } from "./app.controller"; import { AppController } from './app.controller';
import { AppService } from "./app.service"; import { AppService } from './app.service';
import { DbModule } from "./db/db.module"; import { DbModule } from './db/db.module';
import { ThrottlerModule } from '@nestjs/throttler';
import { ConfigModule } from '@nestjs/config';
import { AuthModule } from './auth/auth.module';
import { CredentialsModule } from './credentials/credentials.module';
@Module({ @Module({
imports: [DbModule], imports: [
controllers: [AppController], ThrottlerModule.forRoot([
providers: [AppService], {
ttl: 60000,
limit: 10,
},
]),
ConfigModule.forRoot({
isGlobal: true,
}),
DbModule,
AuthModule,
CredentialsModule,
],
controllers: [AppController],
providers: [AppService],
}) })
export class AppModule {} export class AppModule {}

View File

@ -1,21 +0,0 @@
import { Test } from "@nestjs/testing";
import { AppService } from "./app.service";
describe("AppService", () => {
let service: AppService;
beforeAll(async () => {
const app = await Test.createTestingModule({
providers: [AppService],
}).compile();
service = app.get<AppService>(AppService);
});
describe("getData", () => {
it('should return "Hello API"', () => {
expect(service.getData()).toEqual({ message: "Hello API" });
});
});
});

View File

@ -2,11 +2,7 @@ import { Injectable } from "@nestjs/common";
@Injectable() @Injectable()
export class AppService { export class AppService {
getData(): { message: string } { getData(): { registration: boolean } {
return { message: "Hello API" }; return { registration: false };
} }
} }
const hello: object = {
name: "ABC",
};

View File

@ -6,12 +6,14 @@
import { Logger } from "@nestjs/common"; import { Logger } from "@nestjs/common";
import { NestFactory } from "@nestjs/core"; import { NestFactory } from "@nestjs/core";
import helmet from "helmet";
import { AppModule } from "./app/app.module"; import { AppModule } from "./app/app.module";
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
const globalPrefix = "api"; const globalPrefix = "api";
app.setGlobalPrefix(globalPrefix); app.setGlobalPrefix(globalPrefix);
app.use(helmet());
const port = process.env.PORT || 3000; const port = process.env.PORT || 3000;
await app.listen(port); await app.listen(port);
Logger.log( Logger.log(