Created
June 13, 2018 07:04
-
-
Save thoughtspeed7/815d5ef6f504e6901a80c44c570255e8 to your computer and use it in GitHub Desktop.
Stackdriver Debugger on Google Cloud Functions
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
// om namah shivay | |
const debug = require('@google-cloud/debug-agent').start({ allowExpressions: true }); | |
let debugInitialized; | |
let functionCompleted; | |
let responseJSON; | |
const main = (req, res) => { | |
// always initialize global let variables in the gcf entry point function | |
// because gcf often recycles the execution environment of a previous invocation | |
debugInitialized = false; | |
functionCompleted = false; | |
responseJSON = {}; | |
debug.isReady().then(() => { | |
debugInitialized = true; | |
if (functionCompleted) { | |
console.log('terminating function'); | |
res.json(responseJSON); | |
} | |
}); | |
if (req.query) { | |
responseJSON.param1 = req.query.param1; | |
responseJSON.param2 = req.query.param2; | |
} | |
functionCompleted = true; | |
if (debugInitialized) { | |
console.log('terminating function'); | |
res.json(responseJSON); | |
} | |
}; | |
module.exports = { | |
main | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment