Skip to content

Commit 9720f12

Browse files
authored
fix: drop hardcoded host from HttpAgent options in example frontends (#1488)
@icp-sdk/core resolves the API host from the page: the page origin on localhost, ic0.app and icp0.io, and https://icp-api.io elsewhere. A hardcoded window.location.origin breaks frontends served from a custom domain, which does not serve /api. qrcode and image-classification extend connect-src, since calls now leave the page origin (localhost:8000 locally, icp-api.io on icp.net).
1 parent f31435d commit 9720f12

37 files changed

Lines changed: 5 additions & 41 deletions

File tree

‎motoko/cert-var/frontend/src/actor.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ if (!canisterId) {
1717

1818
export const backend = createActor(canisterId, {
1919
agentOptions: {
20-
host: window.location.origin,
2120
rootKey: canisterEnv?.IC_ROOT_KEY,
2221
},
2322
});

‎motoko/daily_planner/frontend/src/actor.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ if (!canisterId) {
1717

1818
export const backend = createActor(canisterId, {
1919
agentOptions: {
20-
host: window.location.origin,
2120
rootKey: canisterEnv?.IC_ROOT_KEY,
2221
},
2322
});

‎motoko/evm_block_explorer/frontend/src/actor.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ if (!canisterId) {
1818

1919
export const backend = createActor(canisterId, {
2020
agentOptions: {
21-
host: window.location.origin,
2221
rootKey: canisterEnv?.IC_ROOT_KEY,
2322
},
2423
});

‎motoko/filevault/frontend/src/actor.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ if (!canisterId) {
1313
}
1414

1515
const agentOptions = {
16-
host: window.location.origin,
1716
rootKey: canisterEnv?.IC_ROOT_KEY,
1817
};
1918

‎motoko/flying_ninja/frontend/src/actor.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ if (!canisterId) {
1818

1919
export const backend = createActor(canisterId, {
2020
agentOptions: {
21-
host: window.location.origin,
2221
rootKey: canisterEnv?.IC_ROOT_KEY,
2322
},
2423
});

‎motoko/hello_world/frontend/src/actor.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ if (!canisterId) {
1818

1919
export const backend = createActor(canisterId, {
2020
agentOptions: {
21-
host: window.location.origin,
2221
rootKey: canisterEnv?.IC_ROOT_KEY,
2322
},
2423
});

‎motoko/ic-pos/frontend/src/actors.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { IcrcLedgerCanister, IcrcIndexCanister } from "@icp-sdk/canisters/ledger
55
import { createActor } from "./bindings/backend";
66
import { useAuth } from "./lib/auth";
77
import {
8-
host,
98
rootKey,
109
backendCanisterId,
1110
icrc1LedgerCanisterId,
@@ -22,7 +21,7 @@ export function useBackendActor() {
2221
const actor = useMemo(
2322
() =>
2423
createActor(backendCanisterId, {
25-
agentOptions: { host, rootKey, identity },
24+
agentOptions: { rootKey, identity },
2625
}),
2726
[identity]
2827
);
@@ -35,7 +34,7 @@ export function useIcrcLedger() {
3534
const { identity } = useAuth();
3635

3736
return useMemo(() => {
38-
const agent = HttpAgent.createSync({ host, rootKey, identity });
37+
const agent = HttpAgent.createSync({ rootKey, identity });
3938
return IcrcLedgerCanister.create({
4039
agent,
4140
canisterId: Principal.fromText(icrc1LedgerCanisterId),
@@ -48,7 +47,7 @@ export function useIcrcIndex() {
4847
const { identity } = useAuth();
4948

5049
return useMemo(() => {
51-
const agent = HttpAgent.createSync({ host, rootKey, identity });
50+
const agent = HttpAgent.createSync({ rootKey, identity });
5251
return IcrcIndexCanister.create({
5352
agent,
5453
canisterId: Principal.fromText(icrc1IndexCanisterId),

‎motoko/ic-pos/frontend/src/lib/env.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export const icrc1IndexCanisterId = requireCanisterId(
3434
);
3535
export const rootKey = env?.IC_ROOT_KEY;
3636

37-
export const host = window.location.origin;
38-
3937
export const isLocal = /localhost|127\.0\.0\.1/.test(window.location.hostname);
4038

4139
// Internet Identity provider. Locally the network serves II at

‎motoko/llm_chatbot/frontend/src/actor.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ if (!canisterId) {
1616

1717
export const backend = createActor(canisterId, {
1818
agentOptions: {
19-
host: window.location.origin,
2019
rootKey: canisterEnv?.IC_ROOT_KEY,
2120
},
2221
});

‎motoko/random_maze/frontend/src/actor.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ if (!canisterId) {
1717

1818
export const backend = createActor(canisterId, {
1919
agentOptions: {
20-
host: window.location.origin,
2120
rootKey: canisterEnv?.IC_ROOT_KEY,
2221
},
2322
});

0 commit comments

Comments
 (0)