meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ixc2024:tech:tools:backendoftheapplication [2024/05/27 14:49] hibaaixc2024:tech:tools:backendoftheapplication [2024/05/27 18:55] (current) hibaa
Line 139: Line 139:
   - Make sure that you are in the root directoryyour Node app in the terminal, if not, run **'cd *name of your root directory*'**.   - Make sure that you are in the root directoryyour Node app in the terminal, if not, run **'cd *name of your root directory*'**.
   - Install the Google Cloud SDK following the instructions at [[https://cloud.google.com/sdk/docs/install|Google Cloud SDK Installation Guide]]. (__Note:__When asked if you want to log in, input yes and log in to the google cloud account you are using)    - Install the Google Cloud SDK following the instructions at [[https://cloud.google.com/sdk/docs/install|Google Cloud SDK Installation Guide]]. (__Note:__When asked if you want to log in, input yes and log in to the google cloud account you are using) 
-  - Authenticate the Google Cloud SDK by running **‘gcloud auth login’** and following the on-screen instructions. +  - Go back to your Command Prompt and enter the numeric choice associated with your project
-  - Set the project ID by running **‘gcloud config set project PROJECT_ID’**, replacing **‘PROJECT_ID’** with your actual Project ID.+
  
-**Set-Up Service Account** +-> **Set-Up Service Account** 
-  - Go to the [[https://console.cloud.google.com/|Google Cloud Console]]. +  - Go back to your cloud console through [[https://console.cloud.google.com/|Google Cloud Console]]. 
-  - Navigate to IAM & Admin → Service Accounts+  - Navigate through the search bar to **Service Accounts IAM & Admin**
-  - Click on Create Service Account.+  - Click on **Create Service Account**.
   - Provide an appropriate name and description for the service account. For instance, use github-ci-cd as it will be utilized for Github CI/CD.   - Provide an appropriate name and description for the service account. For instance, use github-ci-cd as it will be utilized for Github CI/CD.
-  - Assign the following roles: +  - Click **Continue** on the 2nd step without needing to modify any default information 
-        App Engine Admin +  - Click on **Done** 
-        Cloud Build Service Account +  - Scroll down to the service accounts available, click on the three dots of the one you just created and select Manage keys. 
-        Service Account User +  - Scroll, Click **Add Key → Create New Key**
-        Storage Object Admin +  - Choose the JSON key type and securely download it. Remember, this key grants access to Google Cloud resources, so keep it safely saved.
-  - Click the three dots and select Manage keys. +
-  - Click on Add Key → Create New Key. +
-  - Choose the JSON key type and securely download it. Remember, this key grants access to Google Cloud resources, so keep it safe.+
  
  
 == Version Control == == Version Control ==
  
-**Using GitHub**+-> **Using GitHub**
  
-  Create a Github account or use an existing one.  +  -   Create a Github account or use an existing one.  
- +    Create a new repository, leave all the selected parameters at default 
-  Initialize Git in API Service +  -   Initialize Git in API Service 
- +  -   Go to your Command Pronpmt an run **'git init'** 
-   git remote add origin https://<GITHUB_URL>/waste-backend.git +    Go back to your created Github Repository, scroll down to **…or push an existing repository from the command line**, and copy the code displayed in your Command Prompt
-   git branch -M main +
-   git push -u origin main +
- +
-Please remember to replace **<GITHUB_URL>** with your actual url+
  
 ==Integrating Firebase Authentication WIth Our API Service== ==Integrating Firebase Authentication WIth Our API Service==
  
-**Install Firebase Admin SDK**+-> **Install Firebase Admin SDK**
  
-Install the firebase-admin plugin from npm+Install the firebase-admin plugin from npm in your Command Prompt
  
    npm install firebase-admin    npm install firebase-admin
  
-**Initialize Firebase Admin SDK**+-> **Initialize Firebase Admin SDK**
  
-Create a file named auth.js in your project’s root directory and enter the code below:+In Visual Studio, open the folder you have been working on (In this example it is Waste-Backend), create a file named auth.js in your project’s root directory and enter the code below:
  
    const admin = require('firebase-admin');    const admin = require('firebase-admin');
Line 198: Line 190:
    module.exports = { verifyToken };    module.exports = { verifyToken };
  
-**Creating Express.js Server with Authentication Endpoints**+-> **Creating Express.js Server with Authentication Endpoints**
  
 Create a file named index.js in your projects root directory and enter the code below: Create a file named index.js in your projects root directory and enter the code below:
Line 258: Line 250:
 This will allow you to create endpoints that can be used by the frontend to send or access data. The following URLs can be used to access the different endpoints. This will allow you to create endpoints that can be used by the frontend to send or access data. The following URLs can be used to access the different endpoints.
  
--> Additional resources on how to use firebase authentication with your backend and frontend can be found in the //Additional Resources// section.+__Note:__ Additional resources on how to use firebase authentication with your backend and frontend can be found in the //Additional Resources// section.
  
 ==Deploying API Service to Google Cloud == ==Deploying API Service to Google Cloud ==
  
-**Create app.yaml**+-> **Create app.yaml**
  
 To deploy the app we need to create a configuration file in our project's root directory. This file has to be a yaml file as per Google’s recommendation. For the purpose of this tutorial we will create a file called app.yaml in our root directory and add the settings and routing for Google App Engine. To deploy the app we need to create a configuration file in our project's root directory. This file has to be a yaml file as per Google’s recommendation. For the purpose of this tutorial we will create a file called app.yaml in our root directory and add the settings and routing for Google App Engine.
Line 270: Line 262:
    # [START app_yaml]    # [START app_yaml]
    runtime: nodejs20    runtime: nodejs20
-   service: node-express-api+   entrypoint: node index.js
    # [END app_yaml]    # [END app_yaml]
  
-**Explanation of the Configuration:** +__Notes:__
   * runtime: Specifies the runtime environment (e.g., nodejs20)   * runtime: Specifies the runtime environment (e.g., nodejs20)
   * service: Defines the service name, typically a project-specific prefix or subdomain.   * service: Defines the service name, typically a project-specific prefix or subdomain.
 +  * entrypoint: By default App Engine expects server.js as the entry point but if your app uses anything else then you specify that here.
  
-**Deploy your App Locally**+-> **Deploy your App Locally**
  
-Deploy your Node app by executing the command in root directory of your project+  - Close your command prompt and open it again 
 +  - Run **'gcloud** to make sure that everything is connected 
 +  - Navigate to your project folder **'cd waste-backend'** 
 +  - Run the command **'gcloud init'** 
 +  - Select **'1'** to re-initialize the configuration [default] with new settings 
 +  - Select the email account that you are using in your Cloud Console to perform operations for this configuration 
 +  - Pick the number allocated to your project 
 +  - Deploy your Node app by executing the command in root directory of your project
  
    gcloud app deploy    gcloud app deploy
 +   
 +5. Choose a region where you want your App Engine Application to be located
  
 ====Additional Resources==== ====Additional Resources====