-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathload-from-file.ts
More file actions
47 lines (40 loc) · 1.73 KB
/
Copy pathload-from-file.ts
File metadata and controls
47 lines (40 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* This sample demonstrates loading the default environment configuration profile
* from a TOML file.
*/
// @@@SNIPSTART typescript-env-config-load-default-profile
import { Connection, Client } from '@temporalio/client';
import { loadClientConnectConfig } from '@temporalio/envconfig';
import { resolve } from 'path';
async function main() {
console.log('--- Loading default profile from config.toml ---');
// For this sample to be self-contained, we explicitly provide the path to
// the config.toml file included in this directory.
// By default though, the config.toml file will be loaded from
// ~/.config/temporalio/temporal.toml (or the equivalent standard config directory on your OS).
const configFile = resolve(__dirname, '../config.toml');
// loadClientConnectConfig is a helper that loads a profile and prepares
// the configuration for Connection.connect and Client. By default, it loads the
// "default" profile.
const config = loadClientConnectConfig({
configSource: { path: configFile },
});
console.log(`Loaded 'default' profile from ${configFile}.`);
console.log(` Address: ${config.connectionOptions.address}`);
console.log(` Namespace: ${config.namespace}`);
console.log(` gRPC Metadata: ${JSON.stringify(config.connectionOptions.metadata)}`);
console.log('\nAttempting to connect to client...');
try {
const connection = await Connection.connect(config.connectionOptions);
const client = new Client({ connection, namespace: config.namespace });
console.log('✅ Client connected successfully!');
await connection.close();
} catch (err) {
console.log(`❌ Failed to connect: ${err}`);
}
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
// @@@SNIPEND