With Firebase you can choose between Realtime database & Cloudn Firestore depending on you pricing plan.
With the onSnapshot(..)
function your client app will be updated imidiately after your server get updated, always realtime updates!
Other perks:
- Cloud functions
- Upgrade price plan as you grow
- Firebase is very likely to continue be maintained in the future.
npm install -g firebase-tools
npm install @angular/fire firebase --save
--save, saves it to your json file
firebase init
firebase login
firebase deploy
ionic g service services/firebase
The last thing needed is to make sure caching headers are being set correctly. To do this, add the following snippet to the firebase.json
file to the hosting property:
"headers": [
{
"source": "/build/app/**",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=31536000"
}
]
},
{
"source": "sw.js",
"headers": [
{
"key": "Cache-Control",
"value": "no-cache"
}
]
}
]
For more information about the firebase.json properties, see the Firebase documentation.
The app can now be deployed by running
firebase deploy
After this completes the app will be live.
https://ionicframework.com/docs/publishing/progressive-web-app
Note: Adding ratings is a good example for using a transaction for this particular codelab. However, in a production app you should perform the average rating calculation on a trusted server to avoid manipulation by users. A good way to do this is to write the rating document directly from the client, then use Cloud Functions to update the new restaurant average rating.
Warning: When a transaction fails on the server, the callback is also re-executed repeatedly. Never place logic that modifies app state inside the transaction callback.