From 869c20e0353933520b1f7196c2e7a2079ea7fe9d Mon Sep 17 00:00:00 2001 From: hiimgoodpack Date: Mon, 25 Jan 2021 10:17:22 -0500 Subject: [PATCH] Make default configuration work --- README.md | 10 +++------- config.js | 2 +- secret.js | 10 ++++++++++ secret.js.template | 3 --- 4 files changed, 14 insertions(+), 11 deletions(-) create mode 100755 secret.js delete mode 100755 secret.js.template diff --git a/README.md b/README.md index c11d28a..48d46cf 100644 --- a/README.md +++ b/README.md @@ -33,13 +33,9 @@ npm i ``` This will install all of the node modules. -Then, run: -``` -cp secret.js.template secret.js -``` -This will create a new secret.js based on that template. +***OPTIONAL***: You may want to edit secret.js and have jwtPrivateKey set to a randomly generated key, such as with /dev/urandom. This will allow session cookies to persist after server reboot. -***IMPORTANT***: Open secret.js with your favourite editor, and set the jwtPrivateKey variable to a random string of characters, preferably generated from /dev/urandom or using node's own generation thing. +If you don't set one yourself, a private key will be randomly generated each time the server starts. ***NOTE***: You can edit config.js to tweak some of the settings. You might wanna do that, especially if you are planning to run it on a domain. (setting the address variable) @@ -51,4 +47,4 @@ Just run Brainlet with the command below: node index.js ``` -Good luck! \ No newline at end of file +Good luck! diff --git a/config.js b/config.js index 183c90c..0259e48 100755 --- a/config.js +++ b/config.js @@ -9,7 +9,7 @@ module.exports = { // } //}, corsAllowList: [ 'localhost' ], - mongoUrl: 'mongodb://192.168.0.105:27017/app', + mongoUrl: 'mongodb://localhost:27017/app', bcryptRounds: 10, roleMap: { 'BANNED': 0, diff --git a/secret.js b/secret.js new file mode 100755 index 0000000..726b570 --- /dev/null +++ b/secret.js @@ -0,0 +1,10 @@ +module.exports = { + jwtPrivateKey: 'KEY' +}; + +// Set default values +// You shouldn't need to touch this for configuring this +if (module.exports.jwtPrivateKey === 'KEY') { + console.error('[*] [config] jwtPrivateKey was not specified in secret.js. A randomly generated private key will be used instead'); + module.exports.jwtPrivateKey = require('crypto').randomBytes(129).toString('base64'); +} diff --git a/secret.js.template b/secret.js.template deleted file mode 100755 index 2a3e345..0000000 --- a/secret.js.template +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - jwtPrivateKey: 'KEY' -}; \ No newline at end of file