Created
January 23, 2020 07:01
-
-
Save JustinBeckwith/23113594ba76294ec0e0dce0c7b8a7fb to your computer and use it in GitHub Desktop.
This file contains 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 {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); | |
const client = new SecretManagerServiceClient(); | |
const express = require('express'); | |
const app = express(); | |
let secret; | |
async function getSecret() { | |
if (!secret) { | |
const [version] = await client.accessSecretVersion({ | |
name: process.env.SECRET | |
}); | |
secret = version.payload.data.toString('utf8') || 'Master'; | |
} | |
return secret; | |
} | |
app.get('/', async (req, res) => { | |
console.log('Hello world received a request.'); | |
const secret = await getSecret(); | |
res.send(`Hail ${secret}!`); | |
}); | |
const port = process.env.PORT || 8080; | |
app.listen(port, () => { | |
console.log('Hello world listening on port', port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment