Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
node-bigstream
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
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
bs
node-bigstream
Commits
6478433e
Commit
6478433e
authored
Sep 20, 2019
by
Kamron Aroonrua
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
environment map
parent
41d90907
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
12 deletions
+28
-12
default.json
conf/env/default.json
+6
-1
index.js
conf/env/index.js
+1
-0
context.js
context.js
+21
-11
No files found.
conf/env/default.json
View file @
6478433e
[
[
{
"env"
:
"BSCONFIG_AMQP_TYPE"
,
"conf"
:
"amqp.type"
},
{
"env"
:
"BSCONFIG_AMQP_TYPE"
,
"conf"
:
"amqp.type"
},
{
"env"
:
"BSCONFIG_AMQP_URL"
,
"conf"
:
"amqp.url"
}
{
"env"
:
"BSCONFIG_AMQP_URL"
,
"conf"
:
"amqp.url"
},
{
"env"
:
"BSCONFIG_MEMSTORE_TYPE"
,
"conf"
:
"memstore.type"
},
{
"env"
:
"BSCONFIG_MEMSTORE_URL"
,
"conf"
:
"memstore.url"
},
{
"env"
:
"BSCONFIG_STORAGE_REPOSITORY"
,
"conf"
:
"storage.repository"
},
{
"env"
:
"BSCONFIG_STORAGE_APIHOSTNAME"
,
"conf"
:
"storage.api_hostname"
},
{
"env"
:
"BSCONFIG_AUTH_SECRET_TEXT"
,
"conf"
:
"auth.secret.value"
}
]
]
\ No newline at end of file
conf/env/index.js
0 → 100644
View file @
6478433e
module
.
exports
=
require
(
'./default.json'
);
\ No newline at end of file
context.js
View file @
6478433e
var
_dot
=
require
(
'dot-prop'
);
var
_dot
=
require
(
'dot-prop'
);
var
CONFIG_PATH
=
__dirname
+
'/conf/config'
;
var
CONFIG_PATH
=
__dirname
+
'/conf/config'
;
var
ENV_MAP
=
__dirname
+
'/conf/env'
;
var
cfg
=
require
(
CONFIG_PATH
);
var
cfg
=
require
(
CONFIG_PATH
);
module
.
exports
.
config
=
cfg
;
module
.
exports
.
config
=
cfg
;
...
@@ -16,7 +18,7 @@ module.exports.getConfig = function(name,def,opt){
...
@@ -16,7 +18,7 @@ module.exports.getConfig = function(name,def,opt){
var
bs_cfg
=
{};
var
bs_cfg
=
{};
if
(
option
.
env
){
if
(
option
.
env
){
bs_cfg
=
envcnf
(
''
,
cfg
);
bs_cfg
=
envcnf
(
cfg
);
}
else
{
}
else
{
bs_cfg
=
cfg
;
bs_cfg
=
cfg
;
}
}
...
@@ -30,19 +32,27 @@ module.exports.getConfig = function(name,def,opt){
...
@@ -30,19 +32,27 @@ module.exports.getConfig = function(name,def,opt){
return
ret
;
return
ret
;
}
}
var
envcnf
=
function
(
name
,
init_obj
){
var
envcnf
=
function
(
init_obj
){
var
obj
=
init_obj
||
{};
var
obj
=
init_obj
||
{};
var
env
=
process
.
env
;
var
env
=
process
.
env
;
var
name_pref
=
'bs.config'
;
var
envmap
=
require
(
ENV_MAP
);
// var name_pref = 'bs.config';
if
(
name
){
name_pref
=
name_pref
+
'.'
+
name
;}
// if(name){name_pref=name_pref + '.' + name;}
if
(
env
[
name_pref
]){
obj
=
env
[
name_pref
];}
// if(env[name_pref]){obj=env[name_pref];}
var
nfull
=
name_pref
+
'.'
;
// var nfull = name_pref + '.';
Object
.
keys
(
env
).
forEach
((
k
)
=>
{
// Object.keys(env).forEach((k)=>{
if
(
k
.
startsWith
(
nfull
)){
// if(k.startsWith(nfull)){
var
dotkey
=
k
.
substring
(
nfull
.
length
);
// var dotkey = k.substring(nfull.length);
_dot
.
set
(
obj
,
dotkey
,
env
[
k
]);
// _dot.set(obj,dotkey,env[k]);
// }
// });
if
(
!
Array
.
isArray
(
envmap
)){
return
obj
;}
envmap
.
forEach
((
em
)
=>
{
if
(
em
.
env
&&
em
.
conf
&&
env
[
em
.
env
]){
_dot
.
set
(
obj
,
em
.
conf
,
env
[
em
.
env
]);
}
}
});
});
...
...
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