MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / serve

Function serve

packages/codex-native-api/src/cli.ts:23–69  ·  view source on GitHub ↗
(argv: string[])

Source from the content-addressed store, hash-verified

21}
22
23async function serve(argv: string[]): Promise<void> {
24 const options = parseCliArgs(argv);
25 const defaultCwd = path.resolve(options.cwd ?? process.cwd());
26 const host = normalizeServeHost(options);
27 const service = new CodexNativeApiService({
28 env: process.env,
29 host,
30 port: options.port,
31 authPath: options.authPath,
32 authToken: options.authToken,
33 defaultCwd,
34 providerProfileId: options.providerProfileId,
35 defaultModel: options.defaultModel,
36 });
37
38 let stopped = false;
39 const stop = async (signal: string) => {
40 if (stopped) {
41 return;
42 }
43 stopped = true;
44 process.stdout.write(`stopping: ${signal}\n`);
45 await service.stop();
46 process.exit(0);
47 };
48
49 process.on('SIGINT', () => { void stop('SIGINT'); });
50 process.on('SIGTERM', () => { void stop('SIGTERM'); });
51
52 const binding = await service.start();
53 process.stdout.write('codex-native-api started\n');
54 process.stdout.write(`base_url: ${service.baseUrl}\n`);
55 process.stdout.write(`default_cwd: ${defaultCwd}\n`);
56 process.stdout.write(`provider_profile: ${binding.providerProfileId}\n`);
57 process.stdout.write(`provider_kind: ${binding.providerKind}\n`);
58 process.stdout.write(`provider_display_name: ${binding.providerDisplayName}\n`);
59 process.stdout.write(`auth_path: ${binding.authPath ?? 'none'}\n`);
60 process.stdout.write(`access_scope: ${isLoopbackHost(host) ? 'localhost' : 'public'}\n`);
61
62 if (!isLoopbackHost(host) && !options.authToken) {
63 process.stderr.write(
64 'warning: public bind enabled without --auth-token; anyone who can reach this port can use your logged-in Codex runtime.\n',
65 );
66 }
67
68 await new Promise<void>(() => {});
69}
70
71const parseCliArgs = parseServeCliArgs;
72

Callers 1

mainFunction · 0.85

Calls 7

startMethod · 0.95
normalizeServeHostFunction · 0.85
resolveMethod · 0.80
writeMethod · 0.80
stopFunction · 0.70
isLoopbackHostFunction · 0.70
parseCliArgsFunction · 0.50

Tested by

no test coverage detected