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:
parent
be121ef7ca
commit
d4a224614e
@ -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" });
|
||||
});
|
||||
});
|
||||
});
|
@ -1,11 +1,28 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { AppController } from "./app.controller";
|
||||
import { AppService } from "./app.service";
|
||||
import { DbModule } from "./db/db.module";
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
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({
|
||||
imports: [DbModule],
|
||||
imports: [
|
||||
ThrottlerModule.forRoot([
|
||||
{
|
||||
ttl: 60000,
|
||||
limit: 10,
|
||||
},
|
||||
]),
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
}),
|
||||
DbModule,
|
||||
AuthModule,
|
||||
CredentialsModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
@ -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" });
|
||||
});
|
||||
});
|
||||
});
|
@ -2,11 +2,7 @@ import { Injectable } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getData(): { message: string } {
|
||||
return { message: "Hello API" };
|
||||
getData(): { registration: boolean } {
|
||||
return { registration: false };
|
||||
}
|
||||
}
|
||||
|
||||
const hello: object = {
|
||||
name: "ABC",
|
||||
};
|
||||
|
@ -6,12 +6,14 @@
|
||||
import { Logger } from "@nestjs/common";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
|
||||
import helmet from "helmet";
|
||||
import { AppModule } from "./app/app.module";
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
const globalPrefix = "api";
|
||||
app.setGlobalPrefix(globalPrefix);
|
||||
app.use(helmet());
|
||||
const port = process.env.PORT || 3000;
|
||||
await app.listen(port);
|
||||
Logger.log(
|
||||
|
Loading…
x
Reference in New Issue
Block a user