This is a boilerplate repository (template) to create a Google Cloud Functions service that uses Fastify framework.
The main reason (opinionated) is its schema based approach that make easy to validate and serialize input and outputs.
Even if Fastify is complete (extensible) web framework, it could be used also in a serverless environment keeping in mind "that functions as a service should always use small and focused functions" because "is important to remember that the bigger the application the slower the initial boot will be." (Should you use Fastify in a serverless platform?)
Install Google Functions Framework for Node.js
// Globally
$ npm i -g @google-cloud/functions-framework
// or as development library
$ npm i --save-dev @google-cloud/functions-framework
Run locally with Function Framework
$ npx @google-cloud/functions-framework --target=fastifyFunction
Also a quick npm run dev
command script is available in package.json
$ gcloud functions deploy fastifyFunction \
--runtime nodejs14 --trigger-http --region $GOOGLE_REGION --allow-unauthenticated
$ gcloud functions logs read
$ curl -X POST https://$GOOGLE_REGION-$GOOGLE_PROJECT.cloudfunctions.net/me -H "Content-Type: application/json" -d '{ "name": "World" }'