Skip to content

Instantly share code, notes, and snippets.

@guydumais
Created March 6, 2021 16:14
Show Gist options
  • Save guydumais/8c2f340efe80afef04d0f380be5350a3 to your computer and use it in GitHub Desktop.
Save guydumais/8c2f340efe80afef04d0f380be5350a3 to your computer and use it in GitHub Desktop.
Google Cloud Function Entry Point Example
/**
* 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