Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kus-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Кубота
kus-admin
Commits
6c857434
Commit
6c857434
authored
Mar 16, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENV variables support:
KUS_GENERATOR_PORT KUS_GENERATOR_BACKEND
parent
fd4ec837
Pipeline
#571
failed with stage
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
11 deletions
+30
-11
.env.example
.env.example
+3
-0
api.js
api.js
+13
-2
example.env
example.env
+0
-2
generateRandom.js
src/api/generateRandom.js
+14
-7
No files found.
.env.example
0 → 100644
View file @
6c857434
KUS_GENERATOR_BACKEND=https://api.new.local.vkusvill.testin.ru
KUS_GENERATOR_PORT=4001
\ No newline at end of file
api.js
View file @
6c857434
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
;
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
data
=
require
(
"./db.js"
);
...
...
@@ -14,7 +26,6 @@ const app = App(),
const
fs
=
require
(
'fs'
);
const
tpls
=
{
index
:
fs
.
readFileSync
(
'./index.html'
)
+
''
...
...
example.env
deleted
100644 → 0
View file @
fd4ec837
KUS_DATA_DIR=../../
\ No newline at end of file
src/api/generateRandom.js
View file @
6c857434
...
...
@@ -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
)
{
ctx
.
_r
();
return
;
// everything imported
...
...
@@ -206,6 +212,7 @@ let afterLoaded = async function(infoHash) {
},
index: '
qID
'
} );
let inc = 1;
const A = await readCSV( {
fileName: path.join( base, moreElement.a ),
...
...
@@ -242,7 +249,7 @@ let inc = 1;
let saved = await new Promise((r,j)=>{
var options = {
'
method
': '
POST
',
'
url
':
'
https
:
//api.new.local.vkusvill.testin.ru/api/admin/question/'
,
'
url
':
urlJoin(BACKEND,'
/
api
/
admin
/
question
/
')
,
'
headers
': {
'
Content
-
Type
': '
application
/
json
'
},
...
...
@@ -264,7 +271,7 @@ let inc = 1;
let answerResponse = await new Promise((r,j)=>{
var options = {
'
method
': '
POST
',
'url'
:
'https://api.new.local.vkusvill.testin.ru/api/admin/answer/'
,
'
url
':
urlJoin(BACKEND,'
/
api
/
admin
/
answer
/
')
,
'
headers
': {
'
Content
-
Type
': '
application
/
json
'
},
...
...
@@ -314,14 +321,14 @@ module.exports = {
},
'
/
api
/
database
/
update
': {
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: {},
fn: firstRequest = async function() {
var request = require('
request
');//function(o, fn){fn(false, {body:JSON.stringify(require('
..
/
..
/
data
/
mocked
.
json
'))})};//
var options = {
'
method
': '
GET
',
'url'
:
'https://api.new.local.vkusvill.testin.ru/api/admin/category/'
,
'
url
':
urlJoin(BACKEND,'
/
api
/
admin
/
category
/
')
,
'
headers
': {}
};
request(options, function (error, response){
...
...
@@ -332,7 +339,7 @@ module.exports = {
var options = {
'
method
': '
GET
',
'url'
:
'https://api.new.local.vkusvill.testin.ru/api/admin/tag/'
,
'
url
':
urlJoin(BACKEND,'
/
api
/
admin
/
tag
/
')
,
'
headers
': {}
};
request( options, function( error, response ){
...
...
@@ -341,7 +348,7 @@ module.exports = {
console.log('
Request
:
tag
loaded
');
var options = {
'
method
': '
GET
',
'url'
:
'https://api.new.local.vkusvill.testin.ru/api/admin/question/'
,
'
url
':
urlJoin(BACKEND,'
/
api
/
admin
/
question
/
')
,
'
headers
': {}
};
request( options, function( error, response ){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment