Skip to content

Commit

Permalink
docs(examples/supply-chain-app): print correct web host in the CLI logs
Browse files Browse the repository at this point in the history
1. The logs were showing the bound host which in our case was 0.0.0.0
but that is not accepted by web browsers when you are executing HTTP XHR
requests from Javascript.
2. This change makes it so that even though we bind to 0.0.0.0 the logs
to the person running the example application will show 127.0.0.1.
This might potentially cause further confusion in some people who'd think
that we are binding to 127.0.0.1 based on the logs, but this seems like an
acceptable trade-off for an example which has the number one priority of
being easily digestable.

Fixes #2390

Depends on #3362

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Jul 1, 2024
1 parent 6ef514c commit fa190ed
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README-cactus.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ As blockchain technology proliferates, blockchain integration will become an inc
-p 4200:4200 \
ghcr.io/hyperledger/cactus-example-supply-chain-app:2024-03-08--pr-3059-1
```
3. Wait for the output to show the message `INFO (api-server): Cactus Cockpit reachable http://0.0.0.0:3200`
3. Wait for the output to show the message `INFO (supply-chain-app): SupplyChainApp Web GUI - reachable at: http://127.0.0.1:3200`
4. Token generated by the application is displayed below
5. Visit http://localhost:3200 in a web browser with Javascript enabled and insert the token when prompted
5. Visit http://127.0.0.1:3200 in a web browser with Javascript enabled and insert the token when prompted
6. Use the graphical user interface to create data on both ledgers and observe that a consistent view of the data from different ledgers is provided.

Once the last command has finished executing, open link printed on the console with a web browser of your choice
Expand Down
22 changes: 8 additions & 14 deletions docs/docs/cactus/examples/supply-chain-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Usage

2. a test consortium with multiple members and their Cactus nodes

3. Wait for the output to show the message `INFO (api-server): Cactus Cockpit reachable http://0.0.0.0:3200`
3. Wait for the output to show the message `INFO (api-server): Cactus Cockpit reachable http://127.0.0.1:3200`

4. Visit http://0.0.0.0:3200 in your web browser with Javascript enabled
4. Visit http://127.0.0.1:3200 in your web browser with Javascript enabled


Building and running the container locally
Expand Down Expand Up @@ -76,23 +76,17 @@ On the terminal, issue the following commands (steps 1 to 6) and then perform th

3. `yarn build:dev`

4. `cd ./examples/cactus-example-supply-chain-backend/`

5. `yarn install`

6. `cd ../../`

7. Locate the `.vscode/template.launch.json` file
4. Locate the `.vscode/template.launch.json` file

8. Within that file locate the entry named `"Example: Supply Chain App"`
5. Within that file locate the entry named `"Example: Supply Chain App"`

9. Copy the VSCode debug definition object from 2) to your `.vscode/launch.json` file
6. Copy the VSCode debug definition object from 2) to your `.vscode/launch.json` file

10. At this point the VSCode `Run and Debug` panel on the left should have an option also titled `"Example: Supply Chain App"` which starts the application
7. At this point the VSCode `Run and Debug` panel on the left should have an option also titled `"Example: Supply Chain App"` which starts the application

11. When the application finishes loading, the JWT token generated is displayed on the terminal
8. When the application finishes loading, the JWT token generated is displayed on the terminal

12. Visit http://localhost:3200 in a web browser with Javascript enabled and insert the token when prompted
9. Visit http://localhost:3200 in a web browser with Javascript enabled and insert the token when prompted


Live Reloading the GUI Application
Expand Down
10 changes: 7 additions & 3 deletions examples/cactus-example-supply-chain-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@
2. Observe the example application pulling up in the logs
1. the test ledger containers,
2. a test consortium with multiple members and their Cactus nodes
3. Wait for the output to show the message `INFO (api-server): Cactus Cockpit reachable http://0.0.0.0:3200`
4. Visit http://0.0.0.0:3200 in your web browser with Javascript enabled
3. Wait for the output to show the message `INFO (api-server): Cactus Cockpit reachable http://127.0.0.1:3200`
4. Visit http://127.0.0.1:3200 in your web browser with Javascript enabled

## Building and running the container locally

```sh
# Change directories to the project root
# Build the docker image and tag it as "scaeb" for supply chain app example backend
DOCKER_BUILDKIT=1 docker build -f ./examples/cactus-example-supply-chain-backend/Dockerfile . -t scaeb
DOCKER_BUILDKIT=1 docker build --file \
./examples/cactus-example-supply-chain-backend/Dockerfile \
. \
--tag scaeb \
--tag ghcr.io/hyperledger/cactus-example-supply-chain-app:$(git describe --contains --all HEAD)_$(git rev-parse --short HEAD)_$(date -u +"%Y-%m-%dT%H-%M-%SZ")
# Run the built image with ports mapped to the host machine as you see fit
# The --privileged flag is required because we use Docker-in-Docker for pulling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ export class SupplyChainApp {
properties.cockpitHost = addressInfoCockpit.address;
properties.cockpitPort = addressInfoCockpit.port;
properties.grpcPort = 0; // TODO - make this configurable as well
properties.logLevel = this.options.logLevel || "INFO";
properties.logLevel = "WARN"; // silence the logs about 0.0.0.0 web hosts
properties.authorizationProtocol = AuthorizationProtocol.JSON_WEB_TOKEN;
properties.authorizationConfigJson =
await this.getOrCreateAuthorizationConfig();
Expand All @@ -602,6 +602,12 @@ export class SupplyChainApp {

await apiServer.start();

const restApiUrl = `http://127.0.0.1:${properties.apiPort}`;
this.log.info("Cacti API Server - REST API reachable at: %s", restApiUrl);

const guiUrl = `http://127.0.0.1:${properties.cockpitPort}`;
this.log.info("SupplyChainApp Web GUI - reachable at: %s", guiUrl);

return apiServer;
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"generate-api-server-config": "node ./tools/generate-api-server-config.js",
"sync-ts-config": "TS_NODE_PROJECT=tools/tsconfig.json node --experimental-json-modules --loader ts-node/esm ./tools/sync-npm-deps-to-tsc-projects.ts",
"start:api-server": "node ./packages/cactus-cmd-api-server/dist/lib/main/typescript/cmd/cactus-api.js --config-file=.config.json",
"start:example-supply-chain": "yarn build:dev && cd ./examples/cactus-example-supply-chain-backend/ && yarn && yarn start",
"start:example-supply-chain": "yarn build:dev && cd ./examples/cactus-example-supply-chain-backend/ && yarn start",
"start:example-carbon-accounting": "CONFIG_FILE=examples/cactus-example-carbon-accounting-backend/example-config.json node examples/cactus-example-carbon-accounting-backend/dist/lib/main/typescript/carbon-accounting-app-cli.js",
"start:example-cbdc-bridging-app": "node -r ts-node/register examples/cactus-example-cbdc-bridging-backend/dist/lib/main/typescript/cbdc-bridging-app-cli.js dotenv_config_path=examples/cactus-example-cbdc-bridging-backend/process.env",
"purge-build-cache": "del-cli .build-cache/*",
Expand Down

0 comments on commit fa190ed

Please sign in to comment.