|
1 | | -# Firestore Quickstart |
| 1 | +# Firestore Quickstart: Friendly Eats |
| 2 | + |
| 3 | + |
2 | 4 |
|
3 | 5 | ## Introduction |
4 | 6 |
|
5 | | -FriendlyEats is a restaurant recommendation app built on Firestore. It has offline persistence [enabled](https://github.com/firebase/quickstart-js/blob/a4919505778ae280613662b5e0c64a0127a9d4c9/firestore/scripts/FriendlyEats.js#L33). |
6 | | -For more information about Firestore visit [the docs][firestore-docs]. |
| 7 | +FriendlyEats is a restaurant recommendation app built on Firestore. It was built with the [Angular](https://angular.io/) Javascript framework, and can make use of [Firebase's Local Emulator Suite][emulator-docs] (specifically, the [Authentication](https://firebase.google.com/docs/emulator-suite/connect_auth), [Storage](https://firebase.google.com/docs/emulator-suite/connect_storage), [Functions](https://firebase.google.com/docs/emulator-suite/connect_functions), and [Firestore](https://firebase.google.com/docs/emulator-suite/connect_firestore) emulators) so that the quickstart can be run without needing to create a project in the [Firebase Console](https://console.firebase.google.com). |
| 8 | + |
| 9 | +For more information about Firestore visit the [Firestore docs][firestore-docs]. |
| 10 | + |
| 11 | +For more information about the Firebase Emulator Suite visit the [Emulator Suite docs][emulator-docs] |
7 | 12 |
|
8 | 13 | [firestore-docs]: https://firebase.google.com/docs/firestore/ |
| 14 | +[emulator-docs]: https://firebase.google.com/docs/emulator-suite |
9 | 15 |
|
10 | | -## Setup and run the app |
| 16 | +## Prerequisites |
| 17 | +Before following the steps to build and run this quickstart you will need: |
| 18 | + 1. [Node.Js](https://nodejs.org/en/download) Version 16.0 or higher |
| 19 | + 2. [Java](https://jdk.java.net/) JDK version 11 or higher. |
| 20 | + |
| 21 | +## Configure and run the app locally with emulators: |
11 | 22 |
|
12 | 23 | Follow these steps to setup and run the quickstart: |
13 | 24 |
|
14 | | - 1. Create a Firebase project in the [Firebase Console](https://console.firebase.google.com). |
15 | | - 1. In the Firebase console, enable Anonymous authentication on your project by doing: **Authentication > SIGN-IN METHOD > Anonymous > Enable > SAVE** |
16 | | - 1. In the Firebase console, enable Firestore on your project by clicking **Create Database** in the **Cloud Firestore** section of the console and answering all prompts. |
17 | | - 1. Select testing mode for the security rules |
18 | | - 1. Copy/Download this repo and open this folder in a Terminal. |
| 25 | + 1. Install the Angular CLI if you do not already have it installed on your machine: |
| 26 | + ``` bash |
| 27 | + npm install -g @angular/cli |
| 28 | + ``` |
| 29 | + |
19 | 30 | 1. Install the Firebase CLI if you do not have it installed on your machine: |
20 | 31 | ```bash |
21 | 32 | npm -g i firebase-tools |
22 | 33 | ``` |
23 | | - 1. Set the CLI to use the project you created on step 1: |
24 | | - ```bash |
25 | | - firebase use --add |
26 | | - ``` |
27 | | - 1. Deploy the Firestore security rules and indexes: |
| 34 | + |
| 35 | + 1. Install and build all project dependencies |
28 | 36 | ```bash |
29 | | - firebase deploy --only firestore |
| 37 | + npm install && (cd functions && npm install) |
30 | 38 | ``` |
31 | | - 1. Run a local server: |
| 39 | + |
| 40 | + > **Note:** When modifying the contents of `functions/src`, be sure to run `npm run build` in the `functions/` directory so that Typescript changes can be compiled and present in the next emulator run. |
| 41 | + |
| 42 | + 1. Run and serve the project locally: |
32 | 43 | ```bash |
33 | | - firebase serve |
| 44 | + npm start |
34 | 45 | ``` |
35 | | - 1. As indicated, open [http://localhost:5000](http://localhost:5000) in your browser and try out the app. |
| 46 | + 1. Open [http://localhost:4200](http://localhost:4200) in your browser and try out the app! |
| 47 | + |
| 48 | +## Configure and run the app with the Firebase Console: |
| 49 | + |
| 50 | +Follow these steps to have a working version of the quickstart running with the Firebase console: |
| 51 | + |
| 52 | + > **Note:** In the original application (that runs on the emulators), there is a Firebase Function that updates the `avgRating` field of a restaurant whenever that restaurant recieves a review. While **Authentication**, **Storage**, and **Firestore** are offered as free services through the Firebase console, using Firebase **Functions** on the Firebase Console requires a billing plan. There is a [free tier billing plan](https://firebase.google.com/pricing) that allows up to 2 million free function calls per month, but enabling this plan requires presenting payment information to Firebase. The following instructions, therefore, exclude those steps needed to deploy and host functions on the Firebase Console. All application functionality, other than the auto-updating `avgRating` field for restaurants, is conserved. |
| 53 | + |
| 54 | + 1. Create a new Firebase project in the [Firebase Console](https://console.firebase.google.com) |
| 55 | + |
| 56 | + 2. On the project homepage, select `Web` under `Get Started By Adding Firebase To Your App` and follow prompts to create your app, making sure to **copy the `firebaseConfig` object** when presented. |
| 57 | + |
| 58 | +  |
| 59 | + |
| 60 | +  |
| 61 | + |
| 62 | + 3. With the `firebaseConfig` copied, navigate to `src/environments/environments.prod.ts` and paste the contents of the object into the `environment` object: |
| 63 | + |
| 64 | +  |
| 65 | + |
| 66 | + 4. Back in the Firebase console, enable email and password authentication on your project by doing: **Authentication > SIGN-IN METHOD > Email > Email/Password > SAVE** |
| 67 | + |
| 68 | +  |
| 69 | + |
| 70 | + 5. In the Firebase console, enable Firestore on your project by clicking **Create Database** in the **Cloud Firestore** section of the console and answering all prompts. |
| 71 | + |
| 72 | + * When prompted, select "Start in Test Mode" |
| 73 | +
|
| 74 | +  |
| 75 | +
|
| 76 | + 6. Simmilarly, enable Cloud Storage on your project by clicking **Get Started** in the **Storage** section of the console and answering all prompts. |
| 77 | +
|
| 78 | + * When prompted, select "Start in Test Mode" |
| 79 | +
|
| 80 | +  |
| 81 | +
|
| 82 | + 7. Set the CLI to use the project you created in Step 1: |
| 83 | +
|
| 84 | + ```bash |
| 85 | + firebase --use add |
| 86 | + ``` |
| 87 | +
|
| 88 | + 8. Serve your Angular app and see it connect to the Firebase Console by opening [http://localhost:4200](http://localhost:4200) in your browser! |
| 89 | +
|
| 90 | + ```bash |
| 91 | + npm run production |
| 92 | + ``` |
| 93 | + > **Note:** If you've opted to set up a billing plan and wish to deploy functions as well, replace the `firebase deploy --only firestore` on line 8 of `package.json` with `firebase deploy`. |
| 94 | +
|
| 95 | + 11. (Optional) Populate production Firestore with mock data |
| 96 | +
|
| 97 | + Now that the application is live on the Firebase console, you likely want to add some data to your production Firestore database so that you can see the application in action. Rather than manually adding restaurants and reviews, a convenice script is available to populate your production Firestore database. Run the following command (defined in the `Firestore/` directory's `package.json`) to add mock data: |
| 98 | +
|
| 99 | + ```bash |
| 100 | + npm run populate-production |
| 101 | + ``` |
| 102 | +
|
| 103 | + > **Note:** To ensure that the script runs as intended, make sure that you have correctly populated the `environemnt.prod.ts` file with your Firebase credentials. |
36 | 104 | |
37 | 105 | ## Support |
38 | 106 |
|
39 | 107 | - [Firebase Support](https://firebase.google.com/support/) |
40 | 108 |
|
41 | 109 | ## License |
42 | 110 |
|
43 | | -© Google, 2017. Licensed under an [Apache-2](../LICENSE) license. |
| 111 | +© Google, 2023. Licensed under an [Apache-2](../LICENSE) license. |
0 commit comments