Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Amicale CORE
Seb
Seb Gateway
Commits
ca923410
Verified
Commit
ca923410
authored
Oct 16, 2021
by
Maxime FRIESS
💙
Browse files
[HardConfig] Switch to dotenv
parent
84f4470b
Changes
5
Hide whitespace changes
Inline
Side-by-side
.env.example
0 → 100644
View file @
ca923410
WS_IP=127.0.0.1
WS_PORT=8080
WS_PROXY=false
\ No newline at end of file
.gitignore
View file @
ca923410
...
...
@@ -3,3 +3,4 @@ config/softconfig.json
node_modules
cache.json
*.log
.env
package.json
View file @
ca923410
...
...
@@ -8,6 +8,7 @@
"private"
:
false
,
"type"
:
"module"
,
"dependencies"
:
{
"
dotenv
"
:
"
^10.0.0
"
,
"
ws
"
:
"
^8.2.3
"
},
"scripts"
:
{
...
...
src/config/HardConfig.js
View file @
ca923410
...
...
@@ -17,8 +17,7 @@
* along with Seb-Gateway. If not, see <https://www.gnu.org/licenses/>.
*/
import
fs
from
'
fs
'
;
import
Loggers
from
'
../utils/Logger.js
'
;
import
dotenv
from
'
dotenv
'
;
const
HARDCONFIG_FILE
=
'
config/hardconfig.json
'
;
...
...
@@ -30,52 +29,19 @@ const HARDCONFIG_FILE = 'config/hardconfig.json';
*/
class
_HardConfig
{
constructor
()
{
this
.
__logger
=
Loggers
.
getLogger
(
"
HardConfig
"
);
// Check if config dir exists, create if not.
if
(
!
fs
.
existsSync
(
'
config
'
))
{
this
.
__logger
.
warn
(
"
Config directory doesn't exists, creating...
"
);
try
{
fs
.
mkdirSync
(
'
config
'
);
}
catch
(
e
)
{
this
.
__logger
.
fatal
(
"
Failed to create config directory!
"
,
e
,
1
);
return
;
}
}
if
(
!
fs
.
existsSync
(
HARDCONFIG_FILE
))
{
try
{
fs
.
writeFileSync
(
HARDCONFIG_FILE
,
JSON
.
stringify
(
this
.
__getDefaultConfig
()));
}
catch
(
e
)
{
this
.
__logger
.
fatal
(
"
Failed to create config file!
"
,
e
,
1
);
return
;
}
this
.
__logger
.
fatal
(
"
Hardconfig created. Please edit it to your need and restart Seb-BOT.
"
);
return
;
}
try
{
this
.
__config
=
JSON
.
parse
(
fs
.
readFileSync
(
HARDCONFIG_FILE
,
{
encoding
:
"
utf-8
"
}));
}
catch
(
e
)
{
this
.
__logger
.
fatal
(
"
Failed to read config file!
"
,
e
,
2
);
return
;
}
dotenv
.
config
();
}
getWsIp
()
{
return
this
.
__config
.
ws
.
ip
;
return
process
.
env
.
WS_IP
;
}
getWsPort
()
{
return
this
.
__config
.
ws
.
port
;
return
process
.
env
.
WS_PORT
;
}
getWsProxy
()
{
return
this
.
__config
.
ws
.
proxy
;
}
__getDefaultConfig
()
{
return
{
ws
:
{
ip
:
"
127.0.0.1
"
,
port
:
8080
,
proxy
:
false
}
}
return
process
.
env
.
WS_PROXY
;
}
}
...
...
yarn.lock
View file @
ca923410
...
...
@@ -215,6 +215,11 @@ dot-prop@^5.2.0:
dependencies:
is-obj "^2.0.0"
dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
duplexer3@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
...
...
Write
Preview
Supports
Markdown
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