|
1 | 1 | # Question Service
|
| 2 | + |
| 3 | +## Setting-up MongoDB |
| 4 | + |
| 5 | +> :notebook: If you are familiar to MongoDB and wish to use a local instance, please feel free to do so. This guide utilizes MongoDB Cloud Services. |
| 6 | +
|
| 7 | +1. Set up a MongoDB Shared Cluster by following the steps in this [Guide](../user-service/MongoDBSetup.md). |
| 8 | + |
| 9 | +2. 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. |
| 10 | + |
| 11 | +  |
| 12 | + |
| 13 | +3. Select the `Drivers` option, as we have to link to a Node.js App (Question Service). |
| 14 | + |
| 15 | +  |
| 16 | + |
| 17 | +4. Select `Node.js` in the `Driver` pull-down menu, and copy the connection string. |
| 18 | + |
| 19 | + 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. |
| 20 | + |
| 21 | +  |
| 22 | + |
| 23 | +5. In the `question-service` directory, create a copy of the `.env.sample` file and name it `.env`. |
| 24 | + |
| 25 | +6. Update the `MONGO_URI` of the `.env` file, and paste the string we copied earlier in step 4. |
| 26 | + |
| 27 | +## Setting-up Firebase |
| 28 | + |
| 29 | +1. Go to https://console.firebase.google.com/u/0/. |
| 30 | + |
| 31 | +2. Create a project and choose a project name. Navigate to `Storage` and click on it to activate it. |
| 32 | + |
| 33 | +3. Select `Start in production mode` and your preferred cloud storage region. |
| 34 | + |
| 35 | +4. After Storage is created, go to `Rules` section and set rule to: |
| 36 | + |
| 37 | + ``` |
| 38 | + rules_version = '2'; |
| 39 | + service firebase.storage { |
| 40 | + match /b/{bucket}/o { |
| 41 | + match /{allPaths=**} { |
| 42 | + allow read: if true; |
| 43 | + allow write: if request.auth != null; |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + ``` |
| 48 | + |
| 49 | + 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. |
| 50 | + |
| 51 | +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. |
| 52 | + |
| 53 | +6. In `.env` of question service, replace: |
| 54 | + - `FIREBASE_PROJECT_ID` with `project_id` found in the downloaded json file. |
| 55 | + - `FIREBASE_PRIVATE_KEY` with `private_key` found in the downloaded json file. |
| 56 | + - `FIREBASE_CLIENT_EMAIL` with `client_email` found in the downloaded json file. |
| 57 | + - `FIREBASE_STORAGE_BUCKET` with the folder path of the Storage. It should look something like `gs://<appname>.appspot.com`. |
| 58 | + |
| 59 | +## Running Question Service |
| 60 | + |
| 61 | +1. Follow the instructions [here](https://nodejs.org/en/download/package-manager) to set up Node v20. |
| 62 | + |
| 63 | +2. Open Command Line/Terminal and navigate into the `question-service` directory. |
| 64 | + |
| 65 | +3. Run the command: `npm install`. This will install all the necessary dependencies. |
| 66 | + |
| 67 | +4. Run the command `npm start` to start the Question Service in production mode, or use `npm run dev` for development mode, which includes features like automatic server restart when you make code changes. |
| 68 | + |
| 69 | +5. To view Question Service documentation, go to http://localhost:3000/docs. |
| 70 | + |
| 71 | +6. Using applications like Postman, you can interact with the Question Service on port 3000. If you wish to change this, please update the `.env` file. |
0 commit comments