Skip to content

Commit

Permalink
fix(jsbattle-server): default values of config are not assigned properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jamro committed Jan 18, 2020
1 parent d81b5c9 commit 1fc0433
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
1 change: 0 additions & 1 deletion packages/jsbattle-server/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ module.exports = {
"guard-for-in": "error",
"handle-callback-err": "error",
"id-blacklist": "error",
"id-length": "error",
"id-match": "error",
"implicit-arrow-linebreak": [
"error",
Expand Down
14 changes: 14 additions & 0 deletions packages/jsbattle-server/app/Gateway.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
const { ServiceBroker } = require("moleculer");
const path = require('path')
const _ = require('lodash')

class Gateway {

init(options) {
return new Promise((resolve) => {
const defaultOptions = {
"loglevel": "info",
"data": {
"path": "./jsbattle-data"
},
"web": {
"webroot": path.resolve(__dirname, "./public"),
"host": "127.0.0.1",
"port": "8080",
"gaCode": ""
}
};
options = _.defaultsDeep(options, defaultOptions)
this.broker = new ServiceBroker({
namespace: 'jsbattle',
logLevel: options.loglevel
Expand Down
4 changes: 2 additions & 2 deletions packages/jsbattle-server/app/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ let gateway = new Gateway();
gateway.init({
"loglevel": "info",
"data": {
"path": path.join(__dirname, 'public_html')
"path": path.join(__dirname, 'jsbattle-data')
},
"web": {
"webroot": "./public",
"webroot": path.join(__dirname, 'public'),
"host": "127.0.0.1",
"port": "9000",
"gaCode": "AB-123456789-Z"
Expand Down
1 change: 1 addition & 0 deletions packages/jsbattle-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"express": "^4.17.1",
"hijackresponse": "^4.0.0",
"jsbattle-engine": "^2.7.0",
"lodash": "^4.17.15",
"moleculer": "^0.13.12",
"moleculer-db": "^0.8.4",
"moleculer-web": "^0.8.5",
Expand Down
13 changes: 9 additions & 4 deletions packages/jsbattle/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/jsbattle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"jsbattle-engine": "^2.7.0",
"jsbattle-server": "^2.7.0",
"jsbattle-webpage": "^2.7.1",
"lodash": "^4.17.15",
"path": "^0.12.7",
"yargs": "^15.0.2"
},
Expand Down
22 changes: 7 additions & 15 deletions packages/jsbattle/src/jsbattle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const Gateway = require('jsbattle-server').Gateway;
const path = require('path');
const _ = require('lodash');
const yargs = require('yargs');


Expand All @@ -25,24 +26,15 @@ yargs

},
(argv) => {
let config = {
"loglevel": "info",
"data": {
"path": "./jsbattle-data"
},
"web": {
"webroot": "./public",
"host": "127.0.0.1",
"port": "8080",
"gaCode": ""
}
};
let config = {};
if(argv.config) {
config = require(path.resolve(argv.config));
}
config.web = config.web || {};
config.data = config.data || {};
config.loglevel = argv.loglevel || config.loglevel || "info"
config = _.defaultsDeep(config, {
web: {
webroot: path.resolve(__dirname, 'public')
}
});

let gateway = new Gateway();
gateway.init(config)
Expand Down

0 comments on commit 1fc0433

Please sign in to comment.