From 65c81de4ef1e87dd9383fd0ba1175f8b79bdb994 Mon Sep 17 00:00:00 2001 From: Juan Date: Wed, 22 Jun 2022 08:01:28 +0200 Subject: [PATCH] more env files --- b3-dev/api/api-php-call/calls/index.php | 12 ++++++++++++ b3-dev/api/api-php/index.php | 2 -- b3-dev/node/session3/config.env/.env-sample | 13 +++++++++++++ b3-dev/node/session3/config.env/server.js | 11 +++++++++-- b3-dev/node/session3/config.json/server.js | 23 ++++++++++++++++------- 5 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 b3-dev/node/session3/config.env/.env-sample diff --git a/b3-dev/api/api-php-call/calls/index.php b/b3-dev/api/api-php-call/calls/index.php index fe48c47..da5a761 100644 --- a/b3-dev/api/api-php-call/calls/index.php +++ b/b3-dev/api/api-php-call/calls/index.php @@ -2,6 +2,18 @@ header("Content-type: text/plain;charset=utf-8"); + // curl : + // https://www.php.net/manual/fr/intro.curl.php + // curl basics + // https://weichie.com/blog/curl-api-calls-with-php/ + // curl basics with auth + // https://weichie.com/blog/php-curl-api-calls-authentication/ + // curl en fr + // https://analyse-innovation-solution.fr/publication/fr/php/curl-post-get-proxy-https + // guide du dévbutant + // https://rapidapi.com/blog/how-to-use-an-api-with-php/ + + // vars $api_key = "bc1e13327f7f4876902d4bc45c30e102"; $api_url = "https://api.geoapify.com/v1/"; diff --git a/b3-dev/api/api-php/index.php b/b3-dev/api/api-php/index.php index 0ddbebc..3b41307 100644 --- a/b3-dev/api/api-php/index.php +++ b/b3-dev/api/api-php/index.php @@ -2,8 +2,6 @@ //from : https://api.wordpress.org/secret-key/1.1/salt define('AUTH_KEY', '2(QMu)jt|2!(9t]V!4SB/y,+T]LcvGZ8-sV@vS6RUgR!_]&S}{6/RZjAmLeW28On'); - - function get_client_ip() { $ip = null; diff --git a/b3-dev/node/session3/config.env/.env-sample b/b3-dev/node/session3/config.env/.env-sample new file mode 100644 index 0000000..ffc22fd --- /dev/null +++ b/b3-dev/node/session3/config.env/.env-sample @@ -0,0 +1,13 @@ +# port du server node au démarrage +SERVER_PORT=4444 + +# informations de connexion à la base de donnée ... +# le server +DB_HOST=127.0.0.1 +# le port +DB_PORT=3306 +# user et password +DB_USR=test +DB_PWD=averylongpassword +# nom de la base +DB_NAME=thedatabasename diff --git a/b3-dev/node/session3/config.env/server.js b/b3-dev/node/session3/config.env/server.js index dc2860b..da157b4 100644 --- a/b3-dev/node/session3/config.env/server.js +++ b/b3-dev/node/session3/config.env/server.js @@ -10,10 +10,17 @@ var util = require('util'); // si on veut reste on "write" var logfile = fs.createWriteStream(process.cwd() + '/server.log', { flags: 'w' }); console.log = function () { - logfile.write(util.format.apply(null, arguments) + '\n'); + let args = Array.from(arguments); + args = args.map(function (value) { + datetime=new Date(); + value="\n"+datetime.toLocaleString('fr-FR', {hour12: false}) + " - " + typeof(value) + " - " +value.toString(); + return(value); + }); + logfile.write(args.join('')); process.stdout.write(util.format.apply(null, arguments) + '\n'); } + const server = http.createServer(function (request, response) { parsedUrl = url.parse(request.url, false); json_response(200,{status : "active"},response); @@ -41,7 +48,7 @@ fs.access(local_env_file, fs.constants.R_OK, (err) => { server.listen(process.env.SERVER_PORT || 8080); datetime=new Date(); console.log('server started at :'+datetime.toLocaleString('fr-FR', {hour12: false})); - console.log('server started at :'+datetime.toLocaleString('en-EN'),'server started at :'+datetime); + console.log("coucou",1,'server started at :'+datetime.toLocaleString('en-EN'),'server started at :'+datetime); }); //usefull functions diff --git a/b3-dev/node/session3/config.json/server.js b/b3-dev/node/session3/config.json/server.js index 0bceeae..3547be7 100644 --- a/b3-dev/node/session3/config.json/server.js +++ b/b3-dev/node/session3/config.json/server.js @@ -1,9 +1,17 @@ const http = require('http'); const url = require('url'); +const fs = require('fs'); + +var config=null; +//if config.local.jsoon exists load it +if(fs.existsSync(process.cwd() + '/config.local.json')){ + config = require(process.cwd() + '/config.local.json'); +} +// else load normal config file +else { + config = require(process.cwd() + '/config.json'); +} -// load config file -const config = require(process.cwd() + '/config.json'); - function outputHTML5(status, response, content, title) { response.writeHead(status, { 'Content-Type': 'text/html; charset=utf-8' }); @@ -25,12 +33,13 @@ function outputHTML5(status, response, content, title) response.end(); } +//par defaut on se considère +let env = 'install'; var server = http.createServer(function (request, response) { if(request.url === "/") { - - content = config.staging.config_id; - - outputHTML5(200,response,content,"Server info"); + startup_args = process.argv.slice(2); + content = config[startup_args[0]].config_id; + outputHTML5(200,response,content,"Server info"); } else { outputHTML5(404,response,'Y\'a rien ici',"Oups");