|
1 | 1 | # PeerPrep Backend
|
2 | 2 |
|
3 |
| -> Set-up either a local or cloud MongoDB first, before proceeding to each microservice for more instructions. |
| 3 | +> Before proceeding to each microservice for more instructions: |
| 4 | +
|
| 5 | +1. Set-up either a local or cloud MongoDB. |
| 6 | + |
| 7 | +2. Set-up Firebase. |
4 | 8 |
|
5 | 9 | ## Setting-up local MongoDB (only if you are using Docker)
|
6 | 10 |
|
7 | 11 | 1. In the `backend` directory, create a copy of the `.env.sample` file and name it `.env`.
|
8 | 12 |
|
9 | 13 | 2. To set up credentials for the MongoDB database, update `MONGO_INITDB_ROOT_USERNAME`, `MONGO_INITDB_ROOT_PASSWORD` of the `.env` file.
|
10 | 14 |
|
11 |
| -3. Your local Mongo URI will be `mongodb://<MONGO_INITDB_ROOT_USERNAME>:<MONGO_INITDB_ROOT_PASSWORD>@mongo:27017/`. Take note of it as we will be using in the `.env` file in the various microservices later on. |
| 15 | +3. Your local Mongo URI will be `mongodb://<MONGO_INITDB_ROOT_USERNAME>:<MONGO_INITDB_ROOT_PASSWORD>@mongo:27017/`. Take note of it as we will be using in the `.env` files in the various microservices later on. |
12 | 16 |
|
13 |
| -5. You can view the MongoDB collections locally using Mongo Express. To set up Mongo Express, update `ME_CONFIG_BASICAUTH_USERNAME` and `ME_CONFIG_BASICAUTH_PASSWORD`. The username and password will be the login credentials when you access Mongo Express at http://localhost:8081. |
| 17 | +4. You can view the MongoDB collections locally using Mongo Express. To set up Mongo Express, update `ME_CONFIG_BASICAUTH_USERNAME` and `ME_CONFIG_BASICAUTH_PASSWORD`. The username and password will be the login credentials when you access Mongo Express at http://localhost:8081. |
14 | 18 |
|
15 | 19 | ## Setting-up cloud MongoDB (in production)
|
16 | 20 |
|
|
49 | 53 |
|
50 | 54 | 
|
51 | 55 |
|
52 |
| - |
53 | 56 | 
|
54 | 57 |
|
55 | 58 | 7. Next, click on `Add my Current IP Address`. This will whitelist your IP address and allow you to connect to the MongoDB Database.
|
|
61 | 64 | 9. [Optional] Whitelisting All IP's
|
62 | 65 |
|
63 | 66 | 1. Select `Network Access` from the left side pane on Dashboard.
|
64 |
| -  |
| 67 | + |
| 68 | +  |
65 | 69 |
|
66 | 70 | 2. Click on the `Add IP Address` Button
|
67 |
| -  |
| 71 | + |
| 72 | +  |
68 | 73 |
|
69 | 74 | 3. Select the `ALLOW ACCESS FROM ANYWHERE` Button and Click `Confirm`
|
70 |
| -  |
| 75 | + |
| 76 | +  |
71 | 77 |
|
72 | 78 | 4. Now, any IP Address can access this Database.
|
73 | 79 |
|
74 | 80 | 10. After setting up, go to the Database Deployment Page. You would see a list of the Databases you have set up. Select `Connect` on the cluster you just created earlier.
|
75 | 81 |
|
76 |
| -  |
| 82 | +  |
77 | 83 |
|
78 | 84 | 11. Select the `Drivers` option.
|
79 | 85 |
|
80 |
| -  |
| 86 | +  |
81 | 87 |
|
82 | 88 | 12. Select `Node.js` in the `Driver` pull-down menu, and copy the connection string.
|
83 | 89 |
|
84 | 90 | Notice, you may see `<password>` in this connection string. We will be replacing this with the admin account password that we created earlier on when setting up the Shared Cluster.
|
85 | 91 |
|
86 | 92 | 
|
87 | 93 |
|
88 |
| -13. Your cloud Mongo URI will be the string you copied earlier. Take note of it as we will be using in the `.env` file in the various microservices later on. |
| 94 | +13. Your cloud Mongo URI will be the string you copied earlier. Take note of it as we will be using in the `.env` files in the various microservices later on. |
| 95 | + |
| 96 | +## Setting-up Firebase |
| 97 | + |
| 98 | +1. Go to https://console.firebase.google.com/u/0/. |
| 99 | + |
| 100 | +2. Create a project and choose a project name. Navigate to `Storage` and click on it to activate it. |
| 101 | + |
| 102 | +3. Select `Start in production mode` and your preferred cloud storage region. |
| 103 | + |
| 104 | +4. After Storage is created, go to `Rules` section and set rule to: |
| 105 | + |
| 106 | + ``` |
| 107 | + rules_version = '2'; |
| 108 | + service firebase.storage { |
| 109 | + match /b/{bucket}/o { |
| 110 | + match /{allPaths=**} { |
| 111 | + allow read: if true; |
| 112 | + allow write: if request.auth != null; |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + ``` |
| 117 | + |
| 118 | + This rule ensures that only verified users can upload images while ensuring that URLs of images are public. Remember to click `Publish` to save changes. |
| 119 | + |
| 120 | +5. Go to `Settings`, `Project settings`, `Service accounts` and click `Generate new private key`. This will download a `.json` file, which will contain your credentials. |
| 121 | + |
| 122 | +6. You will need to update the following variables in the `.env` files of the various microservices later on. |
| 123 | + - `FIREBASE_PROJECT_ID` is the value of `project_id` found in the downloaded json file. |
| 124 | + - `FIREBASE_PRIVATE_KEY` is the value of `private_key` found in the downloaded json file. |
| 125 | + - `FIREBASE_CLIENT_EMAIL` is the value of `client_email` found in the downloaded json file. |
| 126 | + - `FIREBASE_STORAGE_BUCKET` is the folder path of the Storage. It should look something like `gs://<appname>.appspot.com`. |
0 commit comments