Skip to content

Commit 43f3283

Browse files
authored
feat: Allow serving sample images from filesystem (#853)
1 parent 4a1a201 commit 43f3283

File tree

4 files changed

+67
-18
lines changed

4 files changed

+67
-18
lines changed

src/ui/README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ This service provides the frontend for the retail store, serving the HTML UI and
1010

1111
The following environment variables are available for configuring the service:
1212

13-
| Name | Description | Default |
14-
| --------------------------------- | ------------------------------------------------------------------------------ | ----------------------- |
15-
| `PORT` | The port which the server will listen on | `8080` |
16-
| `RETAIL_UI_THEME` | Name of the theme for the UI, valid values are `default`, `green`, `orange` | `"default"` |
17-
| `RETAIL_UI_DISABLE_DEMO_WARNINGS` | Disable the UI messages warning about demonstration content | `false` |
18-
| `RETAIL_UI_ENDPOINTS_CATALOG` | The endpoint of the catalog API. If set to `false` uses a mock implementation | `false` |
19-
| `RETAIL_UI_ENDPOINTS_CARTS` | The endpoint of the carts API. If set to `false` uses a mock implementation | `false` |
20-
| `RETAIL_UI_ENDPOINTS_ORDERS` | The endpoint of the orders API. If set to `false` uses a mock implementation | `false` |
21-
| `RETAIL_UI_ENDPOINTS_CHECKOUT` | The endpoint of the checkout API. If set to `false` uses a mock implementation | `false` |
22-
| `RETAIL_UI_CHAT_ENABLED` | Enable the chat bot UI | `false` |
23-
| `RETAIL_UI_CHAT_PROVIDER` | The chat provider to use, value values are `bedrock`, `openai`, `mock` | `""` |
24-
| `RETAIL_UI_CHAT_MODEL` | The chat model to use, depends on the provider. | `""` |
25-
| `RETAIL_UI_CHAT_TEMPERATURE` | Model temperature | `0.6` |
26-
| `RETAIL_UI_CHAT_MAX_TOKENS` | Model maximum response tokens | `300` |
27-
| `RETAIL_UI_CHAT_PROMPT` | Model system prompt | `(see source)` |
28-
| `RETAIL_UI_CHAT_BEDROCK_REGION` | Amazon Bedrock region | `""` |
29-
| `RETAIL_UI_CHAT_OPENAI_BASE_URL` | Base URL for OpenAI endpoint | `http://localhost:8888` |
30-
| `RETAIL_UI_CHAT_OPENAI_API_KEY` | API key for OpenAI endpoint | `""` |
13+
| Name | Description | Default |
14+
| --------------------------------- | ------------------------------------------------------------------------------------------------------ | ----------------------- |
15+
| `PORT` | The port which the server will listen on | `8080` |
16+
| `RETAIL_UI_THEME` | Name of the theme for the UI, valid values are `default`, `green`, `orange` | `"default"` |
17+
| `RETAIL_UI_DISABLE_DEMO_WARNINGS` | Disable the UI messages warning about demonstration content | `false` |
18+
| `RETAIL_UI_PRODUCT_IMAGES_PATH` | Overrides the location where the sample product images are sourced from to use the specified file path | `` |
19+
| `RETAIL_UI_ENDPOINTS_CATALOG` | The endpoint of the catalog API. If set to `false` uses a mock implementation | `false` |
20+
| `RETAIL_UI_ENDPOINTS_CARTS` | The endpoint of the carts API. If set to `false` uses a mock implementation | `false` |
21+
| `RETAIL_UI_ENDPOINTS_ORDERS` | The endpoint of the orders API. If set to `false` uses a mock implementation | `false` |
22+
| `RETAIL_UI_ENDPOINTS_CHECKOUT` | The endpoint of the checkout API. If set to `false` uses a mock implementation | `false` |
23+
| `RETAIL_UI_CHAT_ENABLED` | Enable the chat bot UI | `false` |
24+
| `RETAIL_UI_CHAT_PROVIDER` | The chat provider to use, value values are `bedrock`, `openai`, `mock` | `""` |
25+
| `RETAIL_UI_CHAT_MODEL` | The chat model to use, depends on the provider. | `""` |
26+
| `RETAIL_UI_CHAT_TEMPERATURE` | Model temperature | `0.6` |
27+
| `RETAIL_UI_CHAT_MAX_TOKENS` | Model maximum response tokens | `300` |
28+
| `RETAIL_UI_CHAT_PROMPT` | Model system prompt | `(see source)` |
29+
| `RETAIL_UI_CHAT_BEDROCK_REGION` | Amazon Bedrock region | `""` |
30+
| `RETAIL_UI_CHAT_OPENAI_BASE_URL` | Base URL for OpenAI endpoint | `http://localhost:8888` |
31+
| `RETAIL_UI_CHAT_OPENAI_API_KEY` | API key for OpenAI endpoint | `""` |
3132

3233
## Endpoints
3334

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: MIT-0
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
6+
* software and associated documentation files (the "Software"), to deal in the Software
7+
* without restriction, including without limitation the rights to use, copy, modify,
8+
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so.
10+
*
11+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
12+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
13+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
14+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
15+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
16+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17+
*/
18+
19+
package com.amazon.sample.ui.config;
20+
21+
import org.springframework.beans.factory.annotation.Value;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
24+
import org.springframework.web.reactive.config.WebFluxConfigurer;
25+
26+
@Configuration
27+
public class WebConfig implements WebFluxConfigurer {
28+
29+
@Value("${retail.ui.product-images-path}")
30+
private String productImagesPath;
31+
32+
@Override
33+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
34+
System.out.println(this.productImagesPath);
35+
36+
if (this.productImagesPath != null && !this.productImagesPath.isEmpty()) {
37+
registry
38+
.addResourceHandler("/assets/img/products/**")
39+
.addResourceLocations("file:" + this.productImagesPath);
40+
}
41+
}
42+
}

src/ui/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"type": "java.lang.String",
1111
"description": "Disable the UI messages warning about demonstration content"
1212
},
13+
{
14+
"name": "retail.ui.product-images-path",
15+
"type": "java.lang.String",
16+
"description": "Overrides the location where the sample product images are sourced from to use the specified file path"
17+
},
1318
{
1419
"name": "retail.ui.endpoints.catalog",
1520
"type": "java.lang.String",

src/ui/src/main/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ retail:
1212
ui:
1313
theme: default
1414
disable-demo-warnings: false
15+
product-images-path: # /mnt/products
1516
endpoints:
1617
catalog: # http://localhost:8081
1718
carts: # http://localhost:8082

0 commit comments

Comments
 (0)