-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tech(config): set and get config from json #50
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1 @@ | |||
{"secret":"encrypt","algorithm":"AES"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
algorithm value not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. For now, created the config method and just used the secret. But this solution may not work. Since the config is based on a file on each config set the file will get overridden. So need to think of some alternate solution to maintain the config object instead of keeping the values in a file.
CONVERTED TO DRAFT PR
Converted the PR to |
import { isUrl, isPatternUrl, isPatterObject, isPattern, isPath } from '../util' | ||
|
||
const configData = fs.readFileSync(__dirname + '/config.json', 'utf8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be template literal like below.
const configFile = 'config.json'
fs.readFileSync(`${__dirname}/${configFile}`, 'utf8')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be. Refer Comment
import { isUrl, isPatternUrl, isPatterObject, isPattern, isPath } from '../util' | ||
|
||
const configData = fs.readFileSync(__dirname + '/config.json', 'utf8') | ||
const configObject = JSON.parse(configData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON.parse should be inside try / catch block. there is possibility of circular exception error. can be like below.
let moduleConfig = {}
try {
moduleConfig = JSON.parse(configData)
} catch (e) {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure will work on it.
return { | ||
config: function (config = {}) { | ||
if (Object.keys(config).length === 0) | ||
throw new Error('options is missing') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move all error messages to errorMessages.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure will do that
Get and Set JSON using a key from a file.
Fixes #47