Skip to content
This repository has been archived by the owner on Jul 8, 2021. It is now read-only.

Commit

Permalink
chore: remove forRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
mentos1386 committed Mar 10, 2021
1 parent a25afb8 commit a38e782
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 80 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<a href="https://www.npmjs.com/package/nest-morgan"><img src="https://img.shields.io/npm/v/nest-morgan.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/package/nest-morgan"><img src="https://img.shields.io/npm/l/nest-morgan.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/package/nest-morgan"><img src="https://img.shields.io/npm/dm/nest-morgan.svg" alt="NPM Downloads" /></a>
<a href="https://travis-ci.org/mentos1386/nest-morgan"><img src="https://travis-ci.org/mentos1386/nest-morgan.svg?branch=master" alt="Travis build" /></a>
<a href="https://coveralls.io/github/mentos1386/nest-morgan"><img src="https://coveralls.io/repos/github/mentos1386/nest-morgan/badge.svg?branch=master" alt="Coveralls" /></a>
<a href="https://github.com/mentos1386/nest-morgan/actions/workflows/test.yaml"><img src="https://github.com/mentos1386/nest-morgan/actions/workflows/test.yaml/badge.svg?branch=master" alt="Github Actions - Test" /></a>
</p>

## Description
Expand All @@ -25,6 +24,7 @@ $ npm i --save nest-morgan morgan @types/morgan
### Versions

- **2.x** Is for Nest v7.x
- Remove the need to use `MorganModule.forRoot()` [#17](https://github.com/mentos1386/nest-morgan/issues/17).
- **1.x** Is for Nest v6.x
- **0.x** Is for Nest v5.x

Expand All @@ -36,7 +36,7 @@ $ npm i --save nest-morgan morgan @types/morgan
```ts
@Module({
imports: [...MorganModule.forRoot()],
imports: [MorganModule],
})
export class ApplicationModule {}
```
Expand All @@ -55,7 +55,7 @@ import { APP_INTERCEPTOR } from "@nestjs/core";
import { MorganModule, MorganInterceptor } from "nest-morgan";

@Module({
imports: [MorganModule.forRoot()],
imports: [MorganModule],
providers: [
{
provide: APP_INTERCEPTOR,
Expand Down
10 changes: 2 additions & 8 deletions lib/morgan.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { DynamicModule, Global, Module } from "@nestjs/common";
import { Global, Module } from "@nestjs/common";
import { morganProviders } from "./morgan.providers";

@Global()
@Module({
providers: [...morganProviders],
exports: [...morganProviders],
})
export class MorganModule {
static forRoot(): DynamicModule {
return {
module: MorganModule,
};
}
}
export class MorganModule {}
192 changes: 192 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lib": "lib"
},
"scripts": {
"build": "tsc -p tsconfig.json && cp *.md dist && cp LICENSE dist && cp package.json dist",
"build": "tsc -p tsconfig.build.json && cp *.md dist && cp LICENSE dist && cp package.json dist",
"coverage": "cat ./coverage/lcov.info | coveralls",
"test": "jest"
},
Expand Down Expand Up @@ -35,9 +35,11 @@
"@nestjs/core": "^7.6.13",
"@nestjs/platform-express": "^7.6.13",
"@nestjs/testing": "^7.6.13",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.20",
"@types/morgan": "^1.9.2",
"@types/node": "^14.14.33",
"@types/supertest": "^2.0.10",
"coveralls": "^3.1.0",
"jest": "^26.6.3",
"reflect-metadata": "^0.1.13",
Expand Down
31 changes: 15 additions & 16 deletions test/hello.controller.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { Controller, Get, UseInterceptors } from '@nestjs/common';
import { MorganInterceptor } from '../lib';
import { Controller, Get, UseInterceptors } from "@nestjs/common";
import { MorganInterceptor } from "../lib";

@Controller('')
@Controller("")
export class HelloController {

@Get('common/works')
@UseInterceptors(MorganInterceptor('common'))
@Get("common/works")
@UseInterceptors(MorganInterceptor("common"))
works_common() {
return 'Works';
return "Works";
}

@Get('common/error')
@UseInterceptors(MorganInterceptor('common'))
@Get("common/error")
@UseInterceptors(MorganInterceptor("common"))
error_common() {
throw new Error('Something bad happened');
throw new Error("Something bad happened");
}

@Get('combined/works')
@UseInterceptors(MorganInterceptor('combined'))
@Get("combined/works")
@UseInterceptors(MorganInterceptor("combined"))
works_combined() {
return 'Works';
return "Works";
}

@Get('combined/error')
@UseInterceptors(MorganInterceptor('combined'))
@Get("combined/error")
@UseInterceptors(MorganInterceptor("combined"))
error_combined() {
throw new Error('Something bad happened');
throw new Error("Something bad happened");
}
}
Loading

0 comments on commit a38e782

Please sign in to comment.