Commit 6c857434 by Иван Кубота

ENV variables support:

KUS_GENERATOR_PORT KUS_GENERATOR_BACKEND
parent fd4ec837
Pipeline #571 failed with stage
KUS_GENERATOR_BACKEND=https://api.new.local.vkusvill.testin.ru
KUS_GENERATOR_PORT=4001
\ No newline at end of file
var parsed = require('dotenv').config();
const fs = require( 'fs' );
if(parsed.error){
parsed = require('dotenv').parse(fs.readFileSync('./.env.example', 'utf-8'));
if(!parsed.error){
for (const k in parsed) {
process.env[k] = parsed[k].split('|')[0]
}
}
}
var env = process.env; var env = process.env;
const APP_HOST = env.APP_HOST || "127.0.0.1"; const APP_HOST = env.APP_HOST || "127.0.0.1";
const APP_PORT = env.APP_PORT || 4001; const APP_PORT = env.KUS_GENERATOR_PORT || 4001;
const DB_PATH = env.DB_PATH || "./db/users.json"; const DB_PATH = env.DB_PATH || "./db/users.json";
const data = require("./db.js"); const data = require("./db.js");
...@@ -14,7 +26,6 @@ const app = App(), ...@@ -14,7 +26,6 @@ const app = App(),
const fs = require( 'fs' );
const tpls = { const tpls = {
index: fs.readFileSync('./index.html')+'' index: fs.readFileSync('./index.html')+''
......
KUS_DATA_DIR=../../
\ No newline at end of file
...@@ -104,7 +104,13 @@ const readCSV = async function(scope) { ...@@ -104,7 +104,13 @@ const readCSV = async function(scope) {
}); });
}); });
}; };
let BACKEND = process.env.KUS_GENERATOR_BACKEND;
if(!BACKEND)
throw new Error('No backend specified');
let urlJoin = function(){
let uri = [].slice.call(arguments).join('/');
return uri.substr(0,9)+uri.substr(9).replace(/\/+/g, '/');
};
let afterLoaded = async function(infoHash) { let afterLoaded = async function(infoHash) {
ctx._r(); ctx._r();
return;// everything imported return;// everything imported
...@@ -206,6 +212,7 @@ let afterLoaded = async function(infoHash) { ...@@ -206,6 +212,7 @@ let afterLoaded = async function(infoHash) {
}, },
index: 'qID' index: 'qID'
} ); } );
let inc = 1; let inc = 1;
const A = await readCSV( { const A = await readCSV( {
fileName: path.join( base, moreElement.a ), fileName: path.join( base, moreElement.a ),
...@@ -242,7 +249,7 @@ let inc = 1; ...@@ -242,7 +249,7 @@ let inc = 1;
let saved = await new Promise((r,j)=>{ let saved = await new Promise((r,j)=>{
var options = { var options = {
'method': 'POST', 'method': 'POST',
'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/question/', 'url': urlJoin(BACKEND,'/api/admin/question/'),
'headers': { 'headers': {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
...@@ -264,7 +271,7 @@ let inc = 1; ...@@ -264,7 +271,7 @@ let inc = 1;
let answerResponse = await new Promise((r,j)=>{ let answerResponse = await new Promise((r,j)=>{
var options = { var options = {
'method': 'POST', 'method': 'POST',
'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/answer/', 'url': urlJoin(BACKEND,'/api/admin/answer/'),
'headers': { 'headers': {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
...@@ -314,14 +321,14 @@ module.exports = { ...@@ -314,14 +321,14 @@ module.exports = {
}, },
'/api/database/update': { '/api/database/update': {
method: 'GET', method: 'GET',
summary: 'Reload data from https://api.new.local.vkusvill.testin.ru/api/admin/category/', summary: 'Reload category, tags and questions from '+BACKEND,
options: {}, options: {},
fn: firstRequest = async function() { fn: firstRequest = async function() {
var request = require('request');//function(o, fn){fn(false, {body:JSON.stringify(require('../../data/mocked.json'))})};// var request = require('request');//function(o, fn){fn(false, {body:JSON.stringify(require('../../data/mocked.json'))})};//
var options = { var options = {
'method': 'GET', 'method': 'GET',
'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/category/', 'url': urlJoin(BACKEND,'/api/admin/category/'),
'headers': {} 'headers': {}
}; };
request(options, function (error, response){ request(options, function (error, response){
...@@ -332,7 +339,7 @@ module.exports = { ...@@ -332,7 +339,7 @@ module.exports = {
var options = { var options = {
'method': 'GET', 'method': 'GET',
'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/tag/', 'url': urlJoin(BACKEND,'/api/admin/tag/'),
'headers': {} 'headers': {}
}; };
request( options, function( error, response ){ request( options, function( error, response ){
...@@ -341,7 +348,7 @@ module.exports = { ...@@ -341,7 +348,7 @@ module.exports = {
console.log('Request: tag loaded'); console.log('Request: tag loaded');
var options = { var options = {
'method': 'GET', 'method': 'GET',
'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/question/', 'url': urlJoin(BACKEND,'/api/admin/question/'),
'headers': {} 'headers': {}
}; };
request( options, function( error, response ){ request( options, function( error, response ){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment