Skip to content

wixysam/firestore-connector-node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Corvid Connector for Google Cloud Firestore

This project allows to plug in Google Cloud Firestore into Corvid by Wix site and use it as a Corvid collection database. It is implemented as NodeJS server that can be deployed either to Google Cloud Run or AppEngine. After Connector is deployed it can be used as Corvid External Database.

Getting started

This project assumes you have Google Cloud Project with billing enabled. If you don't have one please follow this free trial guide.

Enable Firestore in Native Mode

Go to https://console.cloud.google.com/firestore/welcome and select Native Mode

Deploying to Cloud Run using Cloud Console

Follow instructions on the Google Cloud Run quickstart guide. In the form of creating service,

  1. Use gcr.io/corvid-api/firestore-connector-node as a container image.
  2. Select Cloud Run (fully managed) as your development platform.
  3. Select us-east1 region.
  4. Select Allow unauthenticated invocations to be able to access the connector from Corvid
  5. Add Environment variable with name of "SECRET_KEY" and put your secret key as a value. This value will be used for connecting Corvid site.
  6. Click Create to deploy the image to Cloud Run and wait for the deployment to finish.

Click the displayed URL link to test the deployed connector. In the browser you should see

{"message":"Missing request context"}

This means that connector is running! Copy the service URL, this is the URL for connecting Firestore to Corvid site

Deployment to Google Cloud Run using gcloud CLI

  • Install the Google Cloud SDK for your operating system;

  • Acquire local credentials;

    gcloud auth application-default login
  • Set project you have created as default by running

    gcloud config set project PROJECTID
  • Deploy the Corvid connector container

    gcloud run deploy --image gcr.io/corvid-api/firestore-connector-node --platform managed --region us-east1 --set-env-vars SECRET_KEY=[YOUR SECRET KEY]
    • Answer y when prompted "Allow unauthenticated invocations to [firestore-connector-node] (y/N)?"

    • After deployment is successful, you should see in the command output something like:

      Service [firestore-connector-node] revision [firestore-connector-node-00001-nep] has been deployed and is serving 100 percent of traffic at https://firestore-connector-node-[autogenerated].run.app

    • Copy the service URL, this is the URL for connecting Firestore to Corvid site

Deployment to Google App Engine using gcloud CLI

  • Check out the source code

     git clone https://github.com/wix-private/firestore-connector-node.git
     cd firestore-connector-node
  • Run deployment command in your connector project folder.

    gcloud app deploy
  • After deployment, access your service at https://<project id>.appspot.com/

Connecting Firestore to Corvid site

Follow instructions here. In the connection Dialog settings put:

  • The connector service URL from steps above in the "Add an endpoint URL" field
  • {"secretKey":"Your Secret Key from the deployment step"} in the Configuration field You should see Firestore collections in the Databases sections of your site.

Development

  • Check out the source code

     git clone https://github.com/wix-private/firestore-connector-node.git
     cd firestore-connector-node
  • Create a GCP Service account

    gcloud iam service-accounts create corvid --description Corvid Dev account --display-name corvid-dev

    and copy its full name from output of

    gcloud iam service-accounts list
  • Generate the Service Account key and save it in gcp-sa-key.json

    gcloud iam service-accounts keys create gcp-sa-key.json --iam-account [SERVICE ACCOUNT FULL NAME]
  • Set environment variable for GCP client libraries

    export GOOGLE_APPLICATION_CREDENTIALS=$PWD/gcp-sa-key.json
  • The Connector is NodeJS express application, start it with

    npm install
    
    npm start

About

Node Firestore Connector example for Wix Data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 98.7%
  • Dockerfile 1.3%