From f79f8eea117bb99e293c6cd2c8015d4309f0ee0e Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Wed, 26 Jun 2024 18:48:12 -0700 Subject: [PATCH] docs(examples/supply-chain-app): print correct web host in the CLI logs 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 --- README-cactus.md | 4 ++-- docs/docs/cactus/examples/supply-chain-app.md | 22 +++++++------------ .../src/main/typescript/supply-chain-app.ts | 8 ++++++- package.json | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README-cactus.md b/README-cactus.md index 3aef25c1a3..c798249b65 100644 --- a/README-cactus.md +++ b/README-cactus.md @@ -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 diff --git a/docs/docs/cactus/examples/supply-chain-app.md b/docs/docs/cactus/examples/supply-chain-app.md index 784d8c9a11..8787eee3d3 100644 --- a/docs/docs/cactus/examples/supply-chain-app.md +++ b/docs/docs/cactus/examples/supply-chain-app.md @@ -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 @@ -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 diff --git a/examples/cactus-example-supply-chain-backend/src/main/typescript/supply-chain-app.ts b/examples/cactus-example-supply-chain-backend/src/main/typescript/supply-chain-app.ts index 3ab9eeba07..dd45b099e9 100644 --- a/examples/cactus-example-supply-chain-backend/src/main/typescript/supply-chain-app.ts +++ b/examples/cactus-example-supply-chain-backend/src/main/typescript/supply-chain-app.ts @@ -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(); @@ -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; } } diff --git a/package.json b/package.json index fb8cd48878..c8e235738d 100644 --- a/package.json +++ b/package.json @@ -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/*",