Firebase + GCP Cloud Functions codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
This codebase was created to demonstrate a fully fledged fullstack application built with Firebase + GCP Cloud Functions including CRUD operations, authentication, routing, pagination, and more.
We've gone to great lengths to adhere to the Firebase + GCP Cloud Functions community styleguides & best practices.
For more information on how to this works with other frontends/backends, head over to the RealWorld repo.
Work in progress!!!
This repo provides an implementation for the backend as defined by the RealWorld API Spec.
Authentication and Database are handled by Firebase. The API is handled by a thin layer made up of Google Cloud Platform Cloud Functions.
Clone this repo.
Setup a new Firebase project, here. Note the Firebase Database URL and replace all instances of TODO-REPLACE-THIS
in the following steps with your newly created database URL/name.
Create a new service account and store the JSON key locally as ./secrets/serviceAccountKey.json
(help). For example:
{
"type": "service_account",
"project_id": "TODO-REPLACE-THIS",
"private_key_id": "...",
"private_key": "-----BEGIN PRIVATE KEY-----\n ... \n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/..."
}
Store Firebase client keys config for Node.js as ./secrets/clientKey.json
(help) - Note: Make sure this is valid JSON. For example:
{
"apiKey": "...",
"authDomain": "TODO-REPLACE-THIS.firebaseapp.com",
"databaseURL": "https://TODO-REPLACE-THIS.firebaseio.com",
"projectId": "TODO-REPLACE-THIS",
"storageBucket": "TODO-REPLACE-THIS.appspot.com",
"messagingSenderId": "..."
}
Execute the following code to populate an .env
file in the project root folder:
rm -f .env && touch .env
echo FIREBASE_SERVER_KEY=`cat ./secrets/serviceAccountKey.json | base64` | tee -a .env
echo FIREBASE_CLIENT_KEY=`cat ./secrets/clientKey.json | base64` | tee -a .env
echo FIREBASE_DATABASE_URL=https://TODO-REPLACE-THIS.firebaseio.com | tee -a .env
When you are done, your .env
file should look something like this
FIREBASE_SERVER_KEY=3M3A0NWpFcFZ ... Y29tIgp9Cg==
FIREBASE_CLIENT_KEY=ewogICJh7HJy ... MzU3NzAiCn0=
FIREBASE_DATABASE_URL=https://TODO-REPLACE-THIS.firebaseio.com
That's it!
npm install
npm test