update process.env with new value

This commit is contained in:
kevmodrome 2020-07-02 21:01:34 +02:00
parent 7a7ad75e12
commit dc35808aea
No known key found for this signature in database
GPG Key ID: E8F9CD141E63BF38
1 changed files with 9 additions and 2 deletions

View File

@ -20,7 +20,13 @@ exports.fetch = async function (ctx) {
}
exports.update = async function (ctx) {
// Do something with ctx.request.body: <{ value: value }>
// Set process.env
const envKeyName = `${ctx.params.key.toUpperCase()}_API_KEY`
process.env[envKeyName] = ctx.request.body.value
// Write to file
// TODO
ctx.status = 200
ctx.message = `Updated ${ctx.params.key} API key succesfully.`
ctx.body = { [ctx.params.key]: ctx.request.body.value }
@ -33,7 +39,8 @@ async function getEnvironmentVariables() {
return data = fs.readFileSync(filePath, 'utf8');
}
async function extractKeys() {
async function extractKeys(content) {
const lines = content.split(/\r?\n/)
// Extract keys here
return []
}