This project was bootstrapped with Create React App.
Open-source 2020 Google Internship project. ScanAndGo is a Spot-as-a-service app within the larger Google Pay app that allows for users to scan barcodes within registered stores for quick checkout without queuing. View the webapp.
- Node js v10 or recommended with a node version manager nvm
- Npm with node or install Yarn
- cd
/client - Install project dependencies by running
yarn install . - Obtain keys for required environment variables specified in
/client/env_templateand/server/env_templateand store it in .env file. This file or any keys should not be checked in. - cd
/server - Install project dependencies by running
yarn install . - Install git-secrets with GCP support
Run yarn dev from /client directory. This runs react-scripts start and watches folder for changes, updating automatically.
Run yarn dev from /server directory. This runs nodemon server.js --watch controllers/ --watch routers/ which starts the express server while watching for changes in the /server/controllers and /server/routers directory, restarting the server when changes are detected.
Alternatively when developing for front-end, we can just do yarn start & to run the express server in the background.
Development Note: We start the express server on port:3143 and proxy unknown requests received by front-end to this port. See /client/package.json:26 where we configure the proxy for the react front-end to http://127.0.0.1:3143 for local development communication between client and server processes.
After setup of gcloud-SDK, run gcloud app deploy in subdirectories /client and /server. Note that /client needs to be built first with yarn build
With this, we will deploy client front-end react app to default service and back-end express app to api service. This is configured in app.yaml within /client and /server directories.
On project root directory, run gcloud app deploy dispatch.yaml to ensure we re-route all requests to */api/* to our api appengine service which is running our express server.
Both the /client and /server NodeJS projects are configured to run test suites with Jest.
In addition to Jest, the server requires supertest and @firebase/testing together with an emulated Cloud Firestore running on our local development environment.
The firebase CLI to run our emulator can be easily installed with yarn global add firebase-tools or npm install -g firebase-tools. Afterwhich, we require a valid Java Runtime Environment installed to run the Firebase emulator. It is suggested to install openjdk-11-jdk on linux machines with sudo apt-get install default-jdk.
Finally, we can start our emulator prior to running any tests with:
firebase emulators:start --only firestore
And test with yarn test. In /server/package.json, we define a pretest script to wipe our emulated database before each run of test to ensure we clean.
Server Test Steps:
firebase emulators:start --only firestoreyarn test- Automatically runs
yarn pretestfirst:curl -X DELETE "http://localhost:8080/emulator/v1/projects/scan-and-go-for-gpay/databases/(default)/documents" NODE_ENV=\"test\" jest
- Automatically runs
Note: Our firestore.js module automatically detects which handle to grab based on the environment variable: NODE_END. When this is "test", we load up the emulatedFirestore.js module rather than use the live Firestore variable (connecting to actual Cloud Firestore DB).