In this part we will explore the Episodes Api code and configuration.
The api is based on the previous examples like ex-10. We will only focus on the significant parts. The api resides in ex-11/got-episodes-api
.
Steps:
-
Observe highlights in changes to the episodes code (ex-10 vs. ex-11)
(Optional - Diff using VSCode)./bin/src-diff.sh
-
App config (./lib/app-config.js)
- Make EPISODES_API_URI config dynamic, read from the environment
- Make QUOTES_API_URL config dynamic, read from the environment
- Make QUOTES_API_URI config dynamic, read from the environment
- Add CLIENT_SECRET config dynamic, read from the environment
- Add CLIENT_ID config dynamic, read from the environment
- Enhance logic that verify config
-
The Quotes worker (./lib/quotes.js)
- One function to get new access token for quotes using OBO
- One function to request a quote with the new access token
- Inspect the steps above and identify the changes to config
- Investigate the Quotes worker code
-
The episodes env file (appsec-course-api-episodes-eq.env) needs to be updated with new config
-
Open appsec-course-api-episodes-eq.env
code $HOME/envs/appsec-course-api-episodes-eq.env
-
Add following config
export NODE_ENV="development" export TENANT_ID="" export CLIENT_ID="" export CLIENT_SECRET='' export EPISODES_API_URI="" export QUOTES_API_URL="http://localhost:3200" export QUOTES_API_URI="" export PORT=3100
-
Add this config - explore the Microsoft Entra ID App registrations to find the proper values.
- Hint: You may have to create a new value for the secret, see exercise 1
-
Explore the Microsoft Entra ID App registrations to find the proper values.
- Hint: You may have to create a new value for the secret
- Do the steps above and update the config
Steps:
(Assuming you are in a terminal window at ./ex-11/got-episodes-api
)
-
Install dependencies
npm install
-
Execute tests
npm test
-
Source the configuration file
source ~/envs/appsec-course-api-episodes-eq.env
-
Run the application
npm start
-
Verify that the application is running at port 3100
- Do the steps above and verify that the API is running