diff --git a/.env b/.env index 97e22b7..3a08757 100644 --- a/.env +++ b/.env @@ -3,13 +3,11 @@ NODE_ENV="development" DEBUG=false MONGODB_URI="mongodb://localhost:27017/headupdb" SERVER_PORT="3200" -SECRET="$2b$10$sMuV/fTCGm9CJGamPFvvte" +SECRET="$2b$10$2.JkQCRUa3fXESy/WyKVWO" SENDGRID_API_KEY="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" SENDGRID_FROM_MAIL="contact@rampeur.fr" SENDGRID_TO_MAIL="rampeur@gmail.com" AUTHORIZATION_PREFIX="Api-Key" -GOLDAPI_URL="https://www.goldapi.io/api" -GOLDAPI_TOKEN="goldapi-akasnfrlfiqv0xw-io" COUCHDB_URL="http://couchdb.unespace.com" COUCHDB_DATABASE="headupdb" COUCHDB_DESIGN="headup_app" diff --git a/.env.development b/.env.development index 52582fa..3a08757 100644 --- a/.env.development +++ b/.env.development @@ -1,15 +1,13 @@ APP_ENV="development" NODE_ENV="development" -DEBUG=true +DEBUG=false MONGODB_URI="mongodb://localhost:27017/headupdb" SERVER_PORT="3200" -SECRET="$2b$10$7LPCMF6razIF744f3k3dLu" +SECRET="$2b$10$2.JkQCRUa3fXESy/WyKVWO" SENDGRID_API_KEY="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" SENDGRID_FROM_MAIL="contact@rampeur.fr" SENDGRID_TO_MAIL="rampeur@gmail.com" AUTHORIZATION_PREFIX="Api-Key" -GOLDAPI_URL="https://www.goldapi.io/api" -GOLDAPI_TOKEN="goldapi-akasnfrlfiqv0xw-io" COUCHDB_URL="http://couchdb.unespace.com" COUCHDB_DATABASE="headupdb" COUCHDB_DESIGN="headup_app" diff --git a/.env.local b/.env.local index 5c9f969..2611b5f 100644 --- a/.env.local +++ b/.env.local @@ -8,8 +8,6 @@ SENDGRID_API_KEY="SG.loEr_gMXRaO6O72zO4u4UA._jb31OOnWApMXfn7e5q9C7lIwzo5FUOoLX4J SENDGRID_FROM_MAIL="contact@rampeur.fr" SENDGRID_TO_MAIL="rampeur@gmail.com" AUTHORIZATION_PREFIX="Api-Key" -GOLDAPI_URL="https://www.goldapi.io/api" -GOLDAPI_TOKEN="goldapi-akasnfrlfiqv0xw-io" COUCHDB_URL="http://couchdb.unespace.com" COUCHDB_DATABASE="headupdb" COUCHDB_DESIGN="headup_app" diff --git a/.env.production b/.env.production index 0898926..fd3f063 100644 --- a/.env.production +++ b/.env.production @@ -2,14 +2,12 @@ APP_ENV="production" NODE_ENV="production" DEBUG=false MONGODB_URI="mongodb://localhost:27017/headupdb" -SERVER_PORT="3030" -SECRET="$2b$10$t1ma1H6HsGi8tMK4GRH5fu" +SERVER_PORT="3200" +SECRET="$2b$10$2.JkQCRUa3fXESy/WyKVWO" SENDGRID_API_KEY="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" SENDGRID_FROM_MAIL="contact@rampeur.fr" SENDGRID_TO_MAIL="rampeur@gmail.com" AUTHORIZATION_PREFIX="Api-Key" -GOLDAPI_URL="https://www.goldapi.io/api" -GOLDAPI_TOKEN="goldapi-akasnfrlfiqv0xw-io" COUCHDB_URL="http://couchdb.unespace.com" COUCHDB_DATABASE="headupdb" COUCHDB_DESIGN="headup_app" diff --git a/app.js b/app.js index f15e50c..7108052 100644 --- a/app.js +++ b/app.js @@ -58,6 +58,7 @@ if(isProduction){ console.log(`${utils.getDateTimeISOString()}`, chalk.red('Unable to connect to the MongoDB database')); }); mongoose.set('debug', process.env.DEBUG); + console.log(`${utils.getDateTimeISOString()}`, chalk.red('debug :'), chalk.yellow(process.env.DEBUG)); } require('./models/mongo/User'); require('./models/mongo/Application'); diff --git a/nodemon.json b/nodemon.json index fa1140d..93455b5 100644 --- a/nodemon.json +++ b/nodemon.json @@ -10,8 +10,6 @@ "SENDGRID_FROM_MAIL": "contact@rampeur.fr", "SENDGRID_TO_MAIL": "rampeur@gmail.com", "AUTHORIZATION_PREFIX": "Api-Key", - "GOLDAPI_URL": "https://www.goldapi.io/api", - "GOLDAPI_TOKEN": "goldapi-akasnfrlfiqv0xw-io", "COUCHDB_URL": "http://couchdb.unespace.com", "COUCHDB_DATABASE": "headupdb", "COUCHDB_DESIGN": "headup_app", diff --git a/package.json b/package.json index 6341ea4..36b25bf 100644 --- a/package.json +++ b/package.json @@ -8,16 +8,16 @@ "Julien Gautier " ], "scripts": { - "mongo:start": "docker run --name hu-mongo -p 27017:27017 mongo & sleep 5", "start": "APP_ENV=production node ./app.js", - "dev": "APP_ENV=development node ./app.js", + "dev": "APP_ENV=development nodemon ./app.js", "local": "APP_ENV=local nodemon ./app.js", "test": "newman run ./tests/api-tests.postman.json -e ./tests/env-api-tests.postman.json", "stop": "lsof -ti :3200 | xargs kill", + "mongo:start": "docker run --name hu-mongo -p 27017:27017 mongo & sleep 5", "mongo:stop": "docker stop hu-mongo && docker rm hu-mongo" }, "engines": { - "node": "^16.20.1 || ^18.16.1 || ^20.3.1" + "node": "^16.20.2 || ^18.19.1 || ^20.11.1" }, "license": "UNLICENSED", "private": true, diff --git a/routes/utils.js b/routes/utils.js index 36a15e3..b9c13f1 100644 --- a/routes/utils.js +++ b/routes/utils.js @@ -1,5 +1,4 @@ const chalk = require('chalk'); -const nodeFetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args)); const utils = { getDateString: () => { @@ -31,37 +30,6 @@ const utils = { } return dateString; - }, - async fetchApi(price, next) { - let url = `${process.env.GOLDAPI_URL}/${price.metal}/${price.currency}`; - // url pour provoquer une erreur en dev : url = `https://www.goldapi.ioppppp/api/${price.metal}/${price.currency}`; - let options = { - method: 'GET', - headers: { - 'x-access-token': process.env.GOLDAPI_TOKEN, - 'Content-Type': 'application/json' - }, - redirect: 'follow' - }; - try { - // Pour tester le retour d'erreur : return { errors: { name: 'error name', message: 'error message', type: 'TYPE', code: 'CODE' } }; - const response = await nodeFetch(url, options); - if (response.status >= 200 && response.status < 400) { - console.log(`${utils.getDateTimeISOString()}`, chalk.green(`${price.metal} | ${price.currency} - Réception du prix spot via API`), chalk.magenta(price.price), `${response.status} ${response.statusText}`); - price = response.json(); - price.then(values => { - values.timestamp *= 1000; - return values; - }); - } else { - console.log(`${utils.getDateTimeISOString()}`, chalk.red(`${price.metal} | ${price.currency} - Erreur ${response.status} ${response.statusText} - Réutilisation du prix stocké`), chalk.magenta(price.price)); - price = { errors: { name: response.statusText, message: `Une erreur ${response.status} '${response.statusText}' est survenue lors de la récupération des prix spots`, type: 'API Error', code: response.status } }; - } - return price; - } catch (error) { - console.log(`${utils.getDateTimeISOString()}`, chalk.red(`${price.metal} | ${price.currency} - fetchApi error`)); - return { errors: { name: error.name, message: error.message, type: error.type, code: error.code } }; - } } };