Skip to content

Commit a7023e0

Browse files
committed
logger
1 parent 67e89eb commit a7023e0

File tree

11 files changed

+83
-58
lines changed

11 files changed

+83
-58
lines changed

README.md

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,40 @@
77

88
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
99
<p align="center">
10-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13-
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14-
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
15-
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
16-
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
17-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
18-
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
19-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
20-
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
10+
2111
</p>
2212
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
2313
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
2414

2515
## Description
2616

27-
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
17+
Orchestrator du projet Sesame
18+
2819

2920
## Installation
3021

3122
```bash
32-
$ npm install
23+
$ yarn install
3324
```
3425

3526
## Running the app
3627

3728
```bash
3829
# development
39-
$ npm run start
30+
$ yarn start:dev
31+
```
4032

41-
# watch mode
42-
$ npm run start:dev
43-
44-
# production mode
45-
$ npm run start:prod
33+
## Variables d'environnements
4634
```
47-
48-
## Test
49-
50-
```bash
51-
# unit tests
52-
$ npm run test
53-
54-
# e2e tests
55-
$ npm run test:e2e
56-
57-
# test coverage
58-
$ npm run test:cov
35+
#Host Redis
36+
REDIS_HOST=redis
37+
#Port Redis
38+
REDIS_PORT=6379
39+
# redis credentials (si ces variables n existe pas, pas d'authentification par defaut
40+
REDIS_USER=monUser
41+
REDIS_PASSWORD=xx
42+
#Log level ( fatal,error,warn,info,debug)
43+
LOG_LEVEL=info
44+
#Nom de la queue (bullMQ) Redis
45+
NAME_QUEUE=backend
5946
```
60-
61-
## Support
62-
63-
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
64-
65-
## Stay in touch
66-
67-
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
68-
- Website - [https://nestjs.com](https://nestjs.com/)
69-
- Twitter - [@nestframework](https://twitter.com/nestframework)
70-
71-
## License
72-
73-
Nest is [MIT licensed](LICENSE).

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM node:18-bookworm-slim
22
LABEL description="Libertech Dev" \
33
maintainer="Libertech <aide@libertech.fr>" \
44
vendor=Libertech \
5-
name="donejsdev"
5+
name="sesame-orchestrator"
66

77
ENV TIMEZONE=Europe/Paris \
88
LANGUAGE=fr_FR.UTF-8 \

docker/docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
version: '3'
22
services:
3-
test-node:
3+
so:
44
build: .
5-
container_name: testsync
5+
container_name: so
66
environment:
77
- NODE_ENV=development
88
- NODE_TLS_REJECT_UNAUTHORIZED=0
9+
- API_KEY=abcdef
910
volumes:
1011
- "..:/data"
1112
ports:

docker/docker-compose.yml.exemple

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '3'
22
services:
3-
test-node:
3+
sesame-orchestrator:
44
build: .
5-
container_name: testsync
5+
container_name: sesame-orchestrator
66
environment:
77
- NODE_ENV=development
88
- NODE_TLS_REJECT_UNAUTHORIZED=0

env.exemple

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REDIS_HOST=redis
2+
REDIS_PORT=6379
3+
LOG_LEVEL=info
4+
NAME_QUEUE=backend

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"passport": "^0.6.0",
3434
"passport-headerapikey": "^1.2.2",
3535
"reflect-metadata": "^0.1.13",
36+
"request-ip": "^3.3.0",
3637
"rxjs": "^7.8.1"
3738
},
3839
"devDependencies": {
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
import { Injectable, UnauthorizedException } from '@nestjs/common';
1+
import {Injectable, Logger, UnauthorizedException} from '@nestjs/common';
22
import { PassportStrategy } from '@nestjs/passport';
33
import { ConfigService } from '@nestjs/config';
44
import Strategy from 'passport-headerapikey';
55

6+
7+
68
@Injectable()
79
export class HeaderApiKeyStrategy extends PassportStrategy(Strategy, 'api-key') {
10+
private readonly logger = new Logger(HeaderApiKeyStrategy.name);
811
constructor(
912
private readonly configService: ConfigService
1013
) {
1114
super({ header: 'Authorization', prefix: 'Bearer ' },
1215
false
1316
);
1417
}
15-
public validate = (apiKey: string, done: (error: Error, data) => {}) => {
16-
console.log('apiKey -' + apiKey + '-')
17-
console.log('API_KEY : ' + process.env.API_KEY)
18+
public validate = ( apiKey: string, done: (error: Error, data) => {}) => {
19+
20+
1821
if (process.env.API_KEY === apiKey) {
19-
console.log('t es ok!')
22+
this.logger.log('Auth OK')
2023
done(null, true);
2124
return
2225
}
23-
console.log('Unauthorized');
26+
this.logger.warn('Auth FAILED' )
2427
done(new UnauthorizedException(), null);
2528
}
2629
}

src/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default () => ({
2+
redis:{
3+
host : process.env.REDIS_HOST || 'localhost',
4+
port : parseInt(process.env.REDIS_PORT) || 6379,
5+
user : process.env.REDIS_USER || '',
6+
password: process.env.REDIS_PASSWORD ||''
7+
},
8+
logLevel: process.env.LOG_LEVEL || 'info',
9+
nameQueue: process.env.NAME_QUEUE || 'backend',
10+
});
11+

src/main.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
import { NestFactory } from '@nestjs/core';
22
import { AppModule } from './app.module';
3+
import ConfigInstance from './config'
4+
import { LogLevel } from '@nestjs/common'
35

46
async function bootstrap() {
5-
const app = await NestFactory.create(AppModule);
7+
const app = await NestFactory.create(AppModule,{logger: setLogLevel() as LogLevel[]});
68
if ( process.env.production != "production"){
79
require("./swagger").default(app)
810
}
911
await app.listen(3000);
1012
}
1113
bootstrap();
14+
15+
16+
function setLogLevel():Array<string>{
17+
let loggerOptions=['error', 'warn','fatal']
18+
let configInstance=ConfigInstance()
19+
switch(configInstance['logLevel']){
20+
case 'fatal' :
21+
loggerOptions=['fatal']
22+
break;
23+
case 'error' :
24+
loggerOptions=['error','fatal']
25+
break;
26+
case 'warn':
27+
loggerOptions=['error', 'warn','fatal']
28+
break;
29+
case 'info' :
30+
loggerOptions=['error', 'warn','fatal','log','verbose']
31+
break;
32+
case 'debug' :
33+
loggerOptions=['error', 'warn','fatal','log','verbose','debug']
34+
break;
35+
}
36+
return loggerOptions
37+
}

src/passwd/passwd.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Controller, Post, Body, Res, UseGuards} from '@nestjs/common';
1+
import {Controller, Post, Body, Res, UseGuards, Logger} from '@nestjs/common';
22
import { PasswdService } from './passwd.service';
33
import {
44
ApiTags,
@@ -13,6 +13,7 @@ import { AuthGuard } from '@nestjs/passport';
1313
@Controller('passwd')
1414
@ApiTags('passwd')
1515
export class PasswdController {
16+
private readonly logger = new Logger(PasswdController.name);
1617
constructor(private passwdService: PasswdService) {
1718
}
1819
@Post()

0 commit comments

Comments
 (0)