MCPcopy Create free account
hub / github.com/dfinity/orbit / getReplicaUrl

Function getReplicaUrl

cli/src/utils.ts:99–126  ·  view source on GitHub ↗
(network: string)

Source from the content-addressed store, hash-verified

97};
98
99export const getReplicaUrl = async (network: string): Promise<string> => {
100 const dfxFile = JSON.parse(await readFile(DFX_PATH, 'utf-8'));
101
102 if (!dfxFile?.networks?.[network]) {
103 throw new Error(`Network '${network}' not found in dfx.json.`);
104 }
105
106 if (dfxFile.networks[network].providers && dfxFile.networks[network].providers.length > 0) {
107 return dfxFile.networks[network].providers[0];
108 }
109
110 if (dfxFile.networks[network].bind) {
111 const bind = dfxFile.networks[network].bind.startsWith('http')
112 ? dfxFile.networks[network].bind
113 : `http://${dfxFile.networks[network].bind}`;
114
115 const validLocalBinds = ['http://localhost', 'http://127.0.0.1', 'http://[::1]'];
116 if (!validLocalBinds.some(validLocalBind => bind.startsWith(validLocalBind))) {
117 throw new Error(
118 `Network '${network}' has a bind URL that is not a valid local bind: ${bind}.`,
119 );
120 }
121
122 return bind;
123 }
124
125 throw new Error(`Network '${network}' does not have a replica URL.`);
126};
127
128export const getIdentityPemFilePath = async (identity: string): Promise<string> => {
129 if (!existsSync(DFX_DEFAULT_IDENTITY_STORE_PATH)) {

Callers 1

publish.tsFile · 0.90

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected