Deploy the function check this url: https://us-central1-tvlk-data-mlplatform-dev.cloudfunctions.net/httpGet?name=Ahmad
Created
March 12, 2019 03:35
-
-
Save faiyaz26/ea4eb5126a51e155bb004642e7ca4f7a to your computer and use it in GitHub Desktop.
basic http function on google cloud function
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
gcloud functions deploy httpGet --runtime nodejs6 --trigger-http |
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
'use strict'; | |
const escapeHtml = require('escape-html'); | |
exports.httpGet = (req, res) => { | |
res.send(`Hello ${escapeHtml(req.query.name || req.body.name || 'World')}!`); | |
}; |
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
{ | |
"name": "hello-get-example", | |
"version": "0.0.1", | |
"private": true, | |
"license": "Apache-2.0", | |
"author": "Google Inc.", | |
"repository": { | |
"type": "git", | |
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" | |
}, | |
"engines": { | |
"node": ">=6" | |
}, | |
"scripts": { | |
"e2e-test": "export FUNCTIONS_CMD='gcloud functions' && sh test/updateFunctions.sh && BASE_URL=\"https://$GCP_REGION-$GCLOUD_PROJECT.cloudfunctions.net/\" ava -T 20s --verbose test/*.test.js", | |
"test": "export FUNCTIONS_CMD='functions-emulator' && sh test/updateFunctions.sh && export BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" && ava -T 20s --verbose -c 1 test/index.test.js", | |
"system-test": "export FUNCTIONS_CMD='functions-emulator' && sh test/updateFunctions.sh && export BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" && ava -T 20s --verbose test/*.test.js" | |
}, | |
"dependencies": { | |
"@google-cloud/debug-agent": "^3.0.0", | |
"escape-html": "^1.0.3", | |
"pug": "^2.0.3", | |
"safe-buffer": "^5.1.2" | |
}, | |
"devDependencies": { | |
"@google-cloud/nodejs-repo-tools": "^3.0.0", | |
"@google-cloud/pubsub": "^0.22.0", | |
"@google-cloud/storage": "^2.0.0", | |
"ava": "^0.25.0", | |
"express": "^4.16.3", | |
"proxyquire": "^2.1.0", | |
"sinon": "^7.0.0", | |
"supertest": "^3.0.0", | |
"uuid": "^3.1.0", | |
"yargs": "^13.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment