-
Notifications
You must be signed in to change notification settings - Fork 272
/
cactus-api.ts
42 lines (35 loc) · 1.08 KB
/
cactus-api.ts
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
#!/usr/bin/env node
import { ApiServer } from "../api-server";
import { ConfigService } from "../config/config-service";
import { Logger, LoggerProvider } from "@hyperledger/cactus-common";
const log: Logger = LoggerProvider.getOrCreate({
label: "cactus-api",
level: "INFO",
});
const main = async () => {
const configService = new ConfigService();
const config = configService.getOrCreate();
const serverOptions = config.getProperties();
LoggerProvider.setLogLevel(serverOptions.logLevel);
if (process.argv[2]?.includes("help")) {
const helpText = ConfigService.getHelpText();
console.log(helpText);
log.info(`Effective Configuration:`);
log.info(JSON.stringify(serverOptions, null, 4));
} else {
const apiServer = new ApiServer({ config: serverOptions });
await apiServer.start();
}
};
export async function launchApp(): Promise<void> {
try {
await main();
log.info(`Cactus API server launched OK `);
} catch (ex) {
log.error(`Cactus API server crashed: `, ex);
process.exit(1);
}
}
if (require.main === module) {
launchApp();
}