Skip to content

anishkny/realworld-firebase-gcp-cloud-functions

Repository files navigation

RealWorld Example App

CircleCI Coveralls Greenkeeper badge Gitter

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!!!

How it works

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.

Getting started

Setup Firebase

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!

Test locally

npm install
npm test

Having trouble setting things up? Come say 👋 here Gitter

About

A Firebase + GCP Cloud Functions backend implementation for RealWorld

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •