Sensor Panel web app (https://sensor-panel.web.app) is a proof of concept app to monitor data sent by a network of Internet of Things (IoT) sensors (currently simulated with a Google Cloud scheduled function that runs every 3 minutes).
- simple cloud deployment pipelines (Firebase)
- single repository for backend and frontend
- shared Typescript models between backend and frontend to simplify iterative changes and API changes
- backend as lambda function
- cloud data store, not database
- self-maintaining with scheduled functions
My considerations for choosing this platform
- Typescript
- React single page app (bootstrapped with create-react-app)
- D3.js data visualisation library
- Located in repository root folder
.
- Typescript
- Express "server" as Firebase Cloud Function https endpoint
- Located in folder
./functions
- Firebase Firestore
There are two steps to run the project locally. Both steps have two options to choose from.
| Option A | Option B | |
|---|---|---|
| Step 1: Dependencies | Docker container | Linux / MacOS native |
| Step 2: Environment | Development mode | Production mode |
The development environment is containerised for convenience (see Dockerfile and docker-compose). Dockerfile is based on https://github.com/AndreySenov/firebase-tools-docker image, but with non-alpine Linux so the shell commands would execute faster in the container.
Start the development container with these commands:
docker-compose up -ddocker-compose exec emulators bash- In the opened bash terminal, continue with the development mode or production mode commands.
- Install Node (version 12, specifically needed for Cloud Functions)
- Install NPM package
firebase-toolsglobally (for version, please see VERSION build argument in docker-compose file) - Install a Java Runtime Environment (for version, see Dockerfile)
- Run
firebase setup:emulators:firestoreto install emulators - In your terminal, continue with the development mode or production mode commands.
Run the following two command sets to get started
npm installto install the depedenciesnpm startto start webpack development server- navigate to http://localhost:3000 to see the FE
- changes to files in
srcfolder will cause the FE to reload - requests to non-static paths (example
GET /api/measurements) are proxied to http://localhost:5001/sensor-panel/us-central1/app, which is the address for development BE
- changes to files in
cd functionsnpm installto install the dependenciesnpm run serveto start the firebase functions and firestore emulator- BE is deployed to http://localhost:5001/sensor-panel/us-central1/
- Changes to files in
functions/srcwill not be active untilnpm run serveis run again - Function logs are accessible at http://localhost:4000/logs
- Changes to files in
- Firestore Emulator UI is accessible at http://localhost:4000/firestore
The production command set builds the FE and BE production versions and emulates the whole environment (FE, BE, Firestore) with some prefilled data in Firestore.
npm install && cd functions && npm install && cd ..to install the dependenciesnpm run build && cd functions && npm run build && cd .. && firebase emulators:start --import="./emulator-data" --only functions,firestore,hosting- FE is deployed to http://localhost:5000
- BE is deployed to http://localhost:5001/sensor-panel/us-central1/
- Function logs are accessible at http://localhost:4000/logs
- Firestore Emulator UI is accessible at http://localhost:4000/firestore
Accepts application/json in format as defined here.