Merge pull request #21078 from sbenhoff007/develop-with-containers-update

Develop with containers minor update & fixed a typo
This commit is contained in:
David Karlsson 2024-10-09 08:26:03 +02:00 committed by GitHub
commit c3b77c9def
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 12 deletions

View File

@ -79,24 +79,17 @@ With this environment up and running, youre ready to make a few changes to th
The greeting at the top of the page is populated by an API call at `/api/greeting`. Currently, it always returns "Hello world!". Youll now modify it to return one of three randomized messages (that you'll get to choose).
1. Open the `backend/src/routes/getGreeting.js` file. This file provides the handler for the API endpoint.
1. Open the `backend/src/routes/getGreeting.js` file in a text editor. This file provides the handler for the API endpoint.
2. Modify the variable at the top to an array of greetings. Feel free to use the following modifications or customize it to your own liking.
2. Modify the variable at the top to an array of greetings. Feel free to use the following modifications or customize it to your own liking. Also, update the endpoint to send a random greeting from this list.
```js {linenos=table,hl_lines=["1-5"],linenostart=1}
```js {linenos=table,hl_lines=["1-5",9],linenostart=1}
const GREETINGS = [
"Whalecome!",
"All hands on deck!",
"Charting the course ahead!",
];
module.exports = async (req, res) => {
...
```
3. Now, update the endpoint to send a random greeting from this list by making the following change:
```js {linenos=table,hl_lines=[3],linenostart=7}
module.exports = async (req, res) => {
res.send({
greeting: GREETINGS[ Math.floor( Math.random() * GREETINGS.length )],
@ -104,7 +97,7 @@ The greeting at the top of the page is populated by an API call at `/api/greetin
};
```
4. If you haven't done so yet, save the file. If you refresh your browser, you should see a new greeting. If you keep refreshing, you should see all of the messages appear.
3. If you haven't done so yet, save the file. If you refresh your browser, you should see a new greeting. If you keep refreshing, you should see all of the messages appear.
![Screenshot of the to-do app with a new greeting](images/develop-app-with-greetings.webp)

View File

@ -1,6 +1,6 @@
---
title: Docker Scout demo
description: Learn about Docke rScout's powerful features for enhanced supply chain security.
description: Learn about Docker Scout's powerful features for enhanced supply chain security.
weight: 20
---