-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nest): code style updates, remove redundant libs (#70)
- Loading branch information
1 parent
d49c859
commit 72f0ddf
Showing
6 changed files
with
32 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import { Test } from "@nestjs/testing"; | ||
import { AppController } from "./app.controller"; | ||
import { AppService } from "./app.service"; | ||
import { Test } from '@nestjs/testing'; | ||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
|
||
describe("App controller", () => { | ||
describe('AppController', () => { | ||
let appController: AppController; | ||
let appService: AppService; | ||
|
||
beforeEach(async () => { | ||
const module = await Test.createTestingModule({ | ||
const testingModule = await Test.createTestingModule({ | ||
controllers: [AppController], | ||
providers: [AppService] | ||
providers: [AppService], | ||
}).compile(); | ||
|
||
appService = module.get<AppService>(AppService); | ||
appController = module.get<AppController>(AppController); | ||
appService = testingModule.get<AppService>(AppService); | ||
appController = testingModule.get<AppController>(AppController); | ||
}); | ||
|
||
describe("hello world", () => { | ||
it("should get response", async () => { | ||
const result = "Hello world"; | ||
jest.spyOn(appService, "get").mockImplementation(() => result); | ||
describe('getHello', () => { | ||
it('should return "Hello world" string', async () => { | ||
const result = 'Hello world'; | ||
jest.spyOn(appService, 'getHello').mockImplementation(() => result); | ||
|
||
expect(await appController.root()).toBe(result); | ||
expect(await appController.getHello()).toBe(result); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { Get, Controller } from "@nestjs/common"; | ||
import { AppService } from "./app.service"; | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { AppService } from './app.service'; | ||
|
||
@Controller() | ||
export class AppController { | ||
constructor(private readonly appService: AppService) {} | ||
|
||
@Get() | ||
root(): string { | ||
return this.appService.get(); | ||
getHello(): string { | ||
return this.appService.getHello(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { AppController } from "./app.controller"; | ||
import { AppService } from "./app.service"; | ||
import { Module } from '@nestjs/common'; | ||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [AppService] | ||
providers: [AppService], | ||
}) | ||
export class ApplicationModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class AppService { | ||
get() { | ||
return "Hello world!"; | ||
getHello(): string { | ||
return 'Hello world!'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,8 @@ | ||
import { NestFactory } from "@nestjs/core"; | ||
import { ApplicationModule } from "./app.module"; | ||
|
||
import * as helmet from "helmet"; | ||
// import * as csurf from "csurf"; | ||
import * as rateLimit from "express-rate-limit"; | ||
import * as compression from "compression"; | ||
|
||
declare const module: any; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { ApplicationModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(ApplicationModule, { cors: true }); | ||
|
||
app.use(helmet()); | ||
//app.use(csurf()); | ||
app.use( | ||
rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100 // limit each IP to 100 requests per windowMs | ||
}) | ||
); | ||
app.use(compression()); | ||
|
||
const app = await NestFactory.create(ApplicationModule); | ||
await app.listen(9000); | ||
|
||
if (module.hot) { | ||
module.hot.accept(); | ||
module.hot.dispose(() => app.close()); | ||
} | ||
} | ||
bootstrap(); |