Skip to content

Instantly share code, notes, and snippets.

@JustinBeckwith
Created January 23, 2020 07:01
Show Gist options
  • Save JustinBeckwith/23113594ba76294ec0e0dce0c7b8a7fb to your computer and use it in GitHub Desktop.
Save JustinBeckwith/23113594ba76294ec0e0dce0c7b8a7fb to your computer and use it in GitHub Desktop.
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