Closed bsde1234 closed 4 years ago
You'll need to:
firebase init
, start the firestore emulator using firebase emulators:start --only firestore
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',
}
}
},
});
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.
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?
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.
@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
@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
firebase.initializeApp(...)
, only the first will succeed, then the other will failstrapi-provider-upload-firebase
requires credentials hardcoded via the admin dashboardstrapi-firebase-auth
requires credentials in a file with the hardcoded name serviceAccountKey.json
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
serviceAccountKey.json
file; this will satisfy strapi-firebase-auth
.GOOGLE_APPLICATION_CREDENTIALS
with the path to the file, probably "./serviceAccountKey.json"
; and this Firestore connector will use those same credentials with zero config.strapi-provider-upload-firebase
, as this will also detect the GOOGLE_APPLICATION_CREDENTIALS
variable with zero config and use the same credentials.
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?