Skip to content

Commit 67337f7

Browse files
fix: replace unsupported 'icp info webserver-port' with 'icp network status --json'
icp-cli does not have an 'info' subcommand. Replace all usages of 'icp info webserver-port' with 'icp network status --json' and parse the gateway_url to extract the port. Also fix the .ic-assets.json5 comment that referenced the non-existent 'icp info security-policy'.
1 parent 1d1ed5d commit 67337f7

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

demos/using-dev-build/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export const readCanisterId = ({
2323
};
2424

2525
function getCanisterHost({ canisterName }: { canisterName: string }): string {
26-
const port = execSync("icp info webserver-port");
26+
const status = JSON.parse(execSync("icp network status --json").toString());
27+
const port = new URL(status.gateway_url).port;
2728
const canisterId = readCanisterId({ canisterName });
2829
return `http://${canisterId}.localhost:${port}`;
2930
}

src/frontend/src/hooks.server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export const handle: Handle = async ({ event, resolve }) => {
1616
)
1717
.toString()
1818
.trim();
19-
const port = execSync("icp info webserver-port").toString().trim();
19+
const port = new URL(
20+
JSON.parse(execSync("icp network status --json").toString()).gateway_url,
21+
).port;
2022
const canisterResponse = await fetch(
2123
`http://${canisterId}.localhost:${port}`,
2224
);

src/try-ii/src/try-ii-frontend/static/.ic-assets.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// Provides a base set of security headers that will work for most dapps.
66
// Any headers you manually specify will override the headers provided by the policy.
7-
// See 'icp info security-policy' to see the policy and for advice on how to harden the headers.
7+
// See https://cli.internetcomputer.org for the policy and for advice on how to harden the headers.
88
// Once you improved the headers for your dapp, set the security policy to "hardened" to disable the warning.
99
// Options are: "hardened" | "standard" | "disabled".
1010
security_policy: "standard",

src/vite-plugins/src/utils.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import type { IncomingMessage, ServerResponse } from "http";
55
import { request } from "undici";
66

77
export const readReplicaPort = (): string => {
8-
const stdout = execSync("icp info webserver-port");
9-
return stdout.toString().trim();
8+
const stdout = execSync("icp network status --json");
9+
const status = JSON.parse(stdout.toString());
10+
return new URL(status.gateway_url).port;
1011
};
1112

1213
export const readCanisterId = ({
@@ -26,14 +27,14 @@ export const readCanisterId = ({
2627
};
2728

2829
export const getReplicaHost = (): string => {
29-
const command = `icp info webserver-port`;
3030
try {
31-
const stdout = execSync(command);
32-
const port = stdout.toString().trim();
31+
const stdout = execSync("icp network status --json");
32+
const status = JSON.parse(stdout.toString());
33+
const port = new URL(status.gateway_url).port;
3334
return `http://127.0.0.1:${port}`;
3435
} catch (e) {
3536
throw Error(
36-
`Could not get replica port '${command}', is the replica running? ${e}`,
37+
`Could not get replica port, is the replica running? ${e}`,
3738
);
3839
}
3940
};

0 commit comments

Comments
 (0)