moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 513 forks source link

Use config file #715

Open bhavin137 opened 6 years ago

bhavin137 commented 6 years ago

I'm trying to pass mosca options as a from a config file. Reading the code, I understand that the config file has to be a node module This is what my config file looks like:

bhavin@home:/opt/mosca$ cat config.js
module.exports = {
    "port": 1883,
    "credentials": "/opt/mosca/credentials.json",
    "verbose": true,
    "logger": { "stream": require('fs').createWriteStream('/opt/mosca/info.log') }
}

but running mosca throws an error like so:

bhavin@home:/opt/mosca$ mosca -c /opt/mosca/config.js
       +++.+++:   ,+++    +++;   '+++    +++. 
      ++.+++.++   ++.++  ++,'+  `+',++  ++,++ 
      +`  +,  +: .+  .+  +;  +; '+  '+  +`  +` 
      +`  +.  +: ,+  `+  ++  +; '+  ;+  +   +. 
      +`  +.  +: ,+  `+   +'    '+      +   +. 
      +`  +.  +: ,+  `+   :+.   '+      +++++. 
      +`  +.  +: ,+  `+    ++   '+      +++++. 
      +`  +.  +: ,+  `+     ++  '+      +   +. 
      +`  +.  +: ,+  `+  +:  +: '+  ;+  +   +. 
      +`  +.  +: .+  .+  +;  +; '+  '+  +   +. 
      +`  +.  +:  ++;++  ++'++   ++'+'  +   +. 
      +`  +.  +:   +++    +++.   ,++'   +   +. 
/opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/lib/server.js:111
      throw new Error(errMessage);
      ^

Error: is not of a type(s) object
    at new Server (/opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/lib/server.js:111:13)
    at /opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/lib/cli.js:197:18
    at makeCall (/opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/node_modules/fastseries/series.js:117:7)
    at ResultsHolder.release (/opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/node_modules/fastseries/series.js:96:9)
    at series (/opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/node_modules/fastseries/series.js:39:14)
    at Object.series (/opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/node_modules/steed/steed.js:90:7)
    at /opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/lib/cli.js:195:11
    at cli (/opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/lib/cli.js:305:12)
    at Object.<anonymous> (/opt/nvm/versions/node/v8.9.3/lib/node_modules/mosca/bin/mosca:19:22)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

Am I missing something here?

P.S: I have ownership of the /opt/mosca folder, so it's not a permissions issue

bhavin137 commented 6 years ago

I was able to get it working by removing the credentials option. It seems "credentials" here refers to ssl credentials (and not auth credentials as I mistakenly assumed)

I think the only way to pass auth credentials file location is through the CLI at the moment @mcollina Is that true? And would it make sense to add a authCredentials option to the config file?

If so, I'd be happy to submit a PR

mcollina commented 6 years ago

Yes, send a PR!

tripflex commented 5 years ago

If that's the case, need to update the wiki too which specifically references credentials: https://github.com/mcollina/mosca/wiki/Authentication-&-Authorization