Last active
August 25, 2021 23:03
-
-
Save khle/35106e4330c535d2320ff178e0caf898 to your computer and use it in GitHub Desktop.
app.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const app = express() | |
const port = process.env.PORT || 3000 | |
app.get('/', (req, res) => { | |
res.send('Hello World!') | |
}) | |
const { DefaultAzureCredential } = require('@azure/identity') | |
const credentials = new DefaultAzureCredential() | |
//console.log(credentials) | |
const { SecretClient } = require('@azure/keyvault-secrets') | |
//Build the URL to reach your key vault | |
const vaultName = 'MyStageAzureSecretVault' | |
const keyVaultUrl = `https://${vaultName}.vault.azure.net` | |
// Then, create our secrets client and connect to the service | |
const secretClient = new SecretClient(keyVaultUrl, credentials) | |
const secretNames = [ | |
'DatabasePassword', | |
'DatabaseUserId' | |
] | |
const promises = secretNames.map(secretName => | |
secretClient.getSecret(secretName) | |
) | |
Promise.all(promises).then(results => { | |
results.forEach(result => { | |
//Optionally add as properties to process.env so they can be available elsewhere | |
process.env[result.name] = result.value | |
}) | |
//Make sure | |
//console.log(process.env.DatabasePassword) | |
//console.log(process.env.DatabaseUserId) | |
app.listen(port, () => { | |
console.log(`Example app listening at http://localhost:${port}`) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment