Created
March 6, 2021 16:14
-
-
Save guydumais/8c2f340efe80afef04d0f380be5350a3 to your computer and use it in GitHub Desktop.
Google Cloud Function Entry Point Example
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
/** | |
* INIT | |
* | |
* Entry point that responds to any HTTP request. | |
* | |
* @param {!express:Request} req HTTP request context. | |
* @param {!express:Response} res HTTP response context. | |
*/ | |
exports.init = ( request, response ) => { | |
/** | |
* PROCESS HTTP REQUEST. | |
*/ | |
let needBlock = false; | |
const getReqHeader = (key) => request.get(key); | |
const Referer = getReqHeader('Referrer'); | |
const user_agent = getReqHeader('User-Agent'); | |
const ref_host = Referer ? new URL(Referer).hostname : ''; | |
const url = Referer ? new URL(request.originalUrl, Referer) : '/'; | |
needBlock = ( ref_host === '' || url === '/') ? true : false; | |
/** | |
* REMAINING CODE GOES HERE. | |
*/ | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment