在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:GoogleCloudPlatform/functions-framework-nodejs开源软件地址:https://github.com/GoogleCloudPlatform/functions-framework-nodejs开源编程语言:TypeScript 94.1%开源软件介绍:Functions Framework for Node.jsAn open source FaaS (Function as a Service) framework based on Express for writing portable Node.js functions -- brought to you by the Google Cloud Functions team. The Functions Framework lets you write lightweight functions that run in many different environments, including:
The framework allows you to go from: /**
* Send "Hello, World!"
* @param req https://expressjs.com/en/api.html#req
* @param res https://expressjs.com/en/api.html#res
*/
exports.helloWorld = (req, res) => {
res.send('Hello, World!');
}; To: curl http://my-url
# Output: Hello, World! All without needing to worry about writing an HTTP server or complicated request handling logic.
Features
InstallationAdd the Functions Framework to your npm install @google-cloud/functions-framework QuickstartsQuickstart: Hello, World on your local machine
Quickstart: Set up a new project
Quickstart: Build a Deployable Container
Run your function on serverless platformsGoogle Cloud FunctionsThe
Node.js 10 runtime on Google Cloud Functions
is based on the Functions Framework. On Cloud Functions, the Functions Framework
is completely optional: if you don't add it to your After you've written your function, you can simply deploy it from your local
machine using the Cloud Run / Cloud Run for AnthosAfter you've written your function, added the Functions Framework and updated your If you want even more control over the environment, you can deploy to Cloud Run for Anthos. With Cloud Run for Anthos, you can run your function on a GKE cluster, which gives you additional control over the environment (including use of GPU-based instances, longer timeouts and more). Container environments based on KnativeCloud Run and Cloud Run for Anthos both implement the Knative Serving API. The Functions Framework is designed to be compatible with Knative environments. Just build and deploy your container to a Knative environment. Configure the Functions FrameworkYou can configure the Functions Framework using command-line flags or environment variables. If you specify both, the environment variable will be ignored.
You can set command-line flags in your "scripts": {
"start": "functions-framework --target=helloWorld"
} Enable Google Cloud Functions EventsThe Functions Framework can unmarshall incoming
Google Cloud Functions event payloads to exports.helloEvents = (data, context) => {
console.log(data);
console.log(context);
}; To enable automatic unmarshalling, set the function signature type to For more details on this signature type, check out the Google Cloud Functions documentation on background functions. Enable CloudEventsThe Functions Framework can unmarshall incoming
CloudEvents payloads to a const functions = require('@google-cloud/functions-framework');
functions.cloudEvent('helloCloudEvents', (cloudevent) => {
console.log(cloudevent.specversion);
console.log(cloudevent.type);
console.log(cloudevent.source);
console.log(cloudevent.subject);
console.log(cloudevent.id);
console.log(cloudevent.time);
console.log(cloudevent.datacontenttype);
}); Advanced DocsMore advanced guides and docs can be found in the ContributingContributions to this library are welcome and encouraged. See CONTRIBUTING for more information on how to get started. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论