Skip to content
Snippets Groups Projects
Commit 2ccc5e86 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat(config): update logging and add envconfiguration handling

parent 5d7b35ae
No related branches found
No related tags found
3 merge requests!27Recette,!26Dev,!1Feat/auth
export const configProd = {
url: process.env.MAIL_URL,
token: process.env.MAIL_TOKEN,
host: 'ram.grandlyon.com',
protocol: 'https',
port: '443',
from: 'inclusionnumerique@grandlyon.com',
from_name: 'Réseau des acteurs de la médiation numérique',
replyTo: 'inclusionnumerique@grandlyon.com',
templates: {
directory: './src/mailer/mail-templates',
verify: {
ejs: 'verify.ejs',
json: 'verify.json',
},
changeEmail: {
ejs: 'changeEmail.ejs',
json: 'changeEmail.json',
},
},
};
export const config = { export const config = {
url: process.env.MAIL_URL, url: process.env.MAIL_URL,
token: process.env.MAIL_TOKEN, token: process.env.MAIL_TOKEN,
host: 'ram.grandlyon.com', host: 'localhost',
protocol: 'https', protocol: 'http',
port: '443', port: '4200',
from: 'inclusionnumerique@grandlyon.com', from: 'inclusionnumerique@grandlyon.com',
from_name: 'Réseau des acteurs de la médiation numérique', from_name: 'Réseau des acteurs de la médiation numérique',
replyTo: 'inclusionnumerique@grandlyon.com', replyTo: 'inclusionnumerique@grandlyon.com',
......
import { Logger } from '@nestjs/common';
import * as dotenv from 'dotenv'; import * as dotenv from 'dotenv';
import { config } from './config'; import { config } from './config';
import { configProd } from './config.prod';
export class ConfigurationService { export class ConfigurationService {
private _config = config; private readonly _config;
constructor() { constructor() {
// Initializing conf with values from var env // Initializing conf with values from var env
if (process.env.NODE_ENV === 'production') {
this._config = configProd;
Logger.log('App started with production conf', 'ConfigurationService');
} else {
this._config = config;
Logger.log('App started with dev conf', 'ConfigurationService');
}
dotenv.config(); dotenv.config();
} }
......
...@@ -28,7 +28,7 @@ export class MailerService { ...@@ -28,7 +28,7 @@ export class MailerService {
subject: subject, subject: subject,
content: html, content: html,
}); });
Logger.log(`[Mailer] Send mail : ${subject}`); Logger.log(`Send mail : ${subject}`, 'Mailer');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.httpService this.httpService
.post(process.env.MAIL_URL, data, { .post(process.env.MAIL_URL, data, {
...@@ -39,11 +39,11 @@ export class MailerService { ...@@ -39,11 +39,11 @@ export class MailerService {
}) })
.subscribe( .subscribe(
(body) => { (body) => {
Logger.log(`[Mailer] Send mail : ${subject} success`); Logger.log(`Send mail : ${subject} success`, 'Mailer');
return resolve(body); return resolve(body);
}, },
(err) => { (err) => {
Logger.error(err); Logger.error(err, 'Mailer');
return reject(err); return reject(err);
} }
); );
......
...@@ -82,7 +82,8 @@ export class StructuresService { ...@@ -82,7 +82,8 @@ export class StructuresService {
resolve(structure); resolve(structure);
}, },
(err) => { (err) => {
Logger.error(`[getCoord] Request error: ${err.config.url}`, err); Logger.error(`Request error: ${err.config.url}`, 'StructureService');
Logger.error(err);
} }
); );
}); });
...@@ -112,7 +113,7 @@ export class StructuresService { ...@@ -112,7 +113,7 @@ export class StructuresService {
public getCoord(numero: string, address: string, zipcode: string): Observable<AxiosResponse<any>> { public getCoord(numero: string, address: string, zipcode: string): Observable<AxiosResponse<any>> {
const req = const req =
'https://download.data.grandlyon.com/geocoding/photon/api' + '?q=' + numero + ' ' + address + ' ' + zipcode; 'https://download.data.grandlyon.com/geocoding/photon/api' + '?q=' + numero + ' ' + address + ' ' + zipcode;
Logger.log(`[StructureService - getCoord] Request : ${req}`); Logger.log(`Request : ${req}`, 'StructureService - getCoord');
return this.httpService.get(encodeURI(req)); return this.httpService.get(encodeURI(req));
} }
} }
TAG=<version number> TAG=<version number>
NODE_ENV=<dev or production>
SERVICE_API_BIND_PORT=<service port> SERVICE_API_BIND_PORT=<service port>
JWT_SECRET=<the secret used to sign jwt token> JWT_SECRET=<the secret used to sign jwt token>
MONGO_ROOT_PASSWORD=<mongo root user password> MONGO_ROOT_PASSWORD=<mongo root user password>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment