arrowheadapps / strapi-connector-firestore

Strapi database connector for Firestore database on Google Cloud Platform.
MIT License
166 stars 15 forks source link

How to run locally and deploy #11

Closed bsde1234 closed 4 years ago

bsde1234 commented 4 years ago

Hi @brettwillis Thanks for this project. I have installed this package and changed ./config/database.js accordingly. What are the next steps to run locally and deploy. Can I deploy my strapi thing to firebase or should I use heroku or something like that?

brettwillis commented 4 years ago

To run locally

You'll need to:

  1. Make sure the Firestore emulator is running: set up your Firebase project using firebase init, start the firestore emulator using firebase emulators:start --only firestore
  2. Make sure you provide the project ID and configure it to connect to the emulator as per the README (configuration shown below),
  3. Boot up Strapi by running strapi develop (or npm run develop) in your strapi directory.
module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'firestore',
      settings: {
        projectId: '{YOUR_PROJECT_ID}',
      },
      options: {
        useEmulator: process.env.NODE_ENV == 'development',
      }
    }
  },
});

To deploy to production

The above configuration will also work for production deployment to App Engine or Cloud Run, because these platforms automagically load the service account credentials for accessing Firestore. Make sure process.env.NODE_ENV != 'development' so that it doesn't attempt to connect to a local emulator in production.

If you wish to deploy on other platforms such as Heroku, this is possible but you will need to manually set up your service account credentials by following the steps here: https://firebase.google.com/docs/admin/setup#initialize-sdk. I haven't personally tried this yet so I can't help you with it.

I deploy the Strapi backend in a Cloud Run container, and I deploy the Strapi admin front-end on Firebase Hosting. I'll eventually add some example setups.

Just a reminder that several things are broken while this in "alpha" state.

Let me know if these steps don't work for you, and I can update the usage instructions accordingly.

bsde1234 commented 4 years ago

you mean we cant upload strapi back end to firebase, so I need to use platforms like heroku. there is also a strapi plugin for strapi for firebase storage i think. how you split strapi front end and back end. is there specific folder for that?

brettwillis commented 4 years ago

you mean we cant upload strapi back end to firebase, so I need to use platforms like heroku.

That's not really what I meant. Your Firebase project is actually a Google Cloud Platform project. So you can use any of the GCP platforms such as App Engine and Cloud Run. I do recommend using App Engine, Cloud Run, or Cloud Functions, because it means you don't have to manually set up authentication with a service account key. It will all work with minimal configuration.

You can use Heroku if you so desire, but anything outside of GCP will require you to manually set up a service account key in order to connect to Firestore.

there is also a strapi plugin for strapi for firebase storage i think.

Yes https://github.com/Lith/strapi-provider-upload-google-cloud-storage. It works great on Cloud Functions, Cloud Run, and App Engine. The same story applies for service account keys if you want to use it outside GCP.

how you split strapi front end and back end. is there specific folder for that?

I'll upload an example project soon.

bsde1234 commented 4 years ago

@brettwillis, Sorry for the late reply. I was referring to https://github.com/bentrynning/strapi-provider-upload-firebase , Is it possible the run the whole strapi project in firebase? There is also auth plugin here

brettwillis commented 3 years ago

@bsde1234 , hmmm, I'm looking at both of those and it seems they are both set up in a way that doesn't really play nice with eachother or this Firestore connector. I haven't actually tried them but this is what I can gather

I feel that the way I have done it is much more flexible and powerful, and those others are not compatible with this or eachother because of the way they are hardcoded.

Let me know if you have a different perspective or experience?

This Firestore connector does not hard code the way that configuration and credentials are provided, and it can rely on the way Firestore looks up GOOGLE_APPLICATION_CREDENTIALS environment variable (can contain JSON, or path to JSON file) or automatically detects credentials when zero config is provided.

It is possible that I could try to detect the presence of the Firebase SDK, and then get the credentials from an already initialised Firebase app. Please create a separate issue for this if you think it is worthwhile.

For now my recommendation is