Skip to content

synapseinsights/tastespace-serverless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tastespace-serverless

This repo contains the code for a "serverless" backend using Google Firebase Cloud Functions and FireStore database. It's incredibly simple and just acts as a CRUD app with defined endpoints and database changes.

Running and developing

Since this setup is "serverless" you can't simply run npm start or npm run start and browse to a localhost. Instead do the following:

  1. Make sure you have firebase tools installed: npm install -g firebase-tools
  2. Install package dependencies within the functions folder: cd functions && npm install
  3. Emulate firebase locally: serve

To deploy simply use: deploy

From here it's possible to hit an endpoint using Or by using Postman or curl (assuming it's not under auth):

curl -G "urlReturnedByDeployCommandAbove/api/doc" #GET
curl -d '{"data": "object"}' -H "Content-Type: application/json" -X POST "endpointURL" #POST
curl -X DELETE "endpointURLForSpecificItem" #DELETE


File description/layout

  1. functions/package.json - defines dependencies and npm commands for running the app (like requirements.txt in python)
  2. functions/package-lock.json - a more detailed version of the above, designed to be put under version control
  3. functions/index.js - core setup of the app (e.g. registering endpoints, overall authentication handling)
  4. functions/model.js - defines the database CRUD operations (create, read, update, delete) for different Firestore collections
  5. functions/controller.js - logic for each endpoint defined in index.js
  6. firebase.json - config file for what happens when the app is deployed to Firebase
  7. public/* - autogenerated html templates

Dependency descriptions

  1. dotenv dontenv allows us to load app configuration files from a .env file in the root of the app directory
  2. express express is the core framework for server and route creation (like Flask or Sanic)
  3. firebase firebase is for database read/write operations
  4. firebase-admin firebase-admin is for database configuration and user authorization
  5. babel and babel-preset-env these packages are for "transpiling", i.e. allowing us to write javascript using the most modern syntax (e.g. import) while allowing compatibility with various node versions that may not support the new syntax

Useful guides/explainers/howtos

GH gist setup
Serverless setup

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published