MCPcopy Index your code
hub / github.com/zenstackhq/zenstack / startServer

Function startServer

packages/cli/src/actions/proxy.ts:430–481  ·  view source on GitHub ↗
(
    client: ClientContract<SchemaDef>,
    schema: any,
    options: Options,
    authDb: ClientContract<SchemaDef>,
)

Source from the content-addressed store, hash-verified

428}
429
430function startServer(
431 client: ClientContract<SchemaDef>,
432 schema: any,
433 options: Options,
434 authDb: ClientContract<SchemaDef>,
435) {
436 const app = createProxyApp(
437 client,
438 schema,
439 authDb,
440 options.studioAuthKey
441 ? {
442 studioAuthKey: options.studioAuthKey,
443 signatureToleranceSecs: options.signatureToleranceSecs,
444 }
445 : undefined,
446 );
447
448 const server = app.listen(options.port, () => {
449 console.log(`ZenStack proxy server is running on port: ${options.port}`);
450 console.log(`You can visit ZenStack Studio at: ${colors.blue('https://studio.zenstack.dev')}`);
451 });
452
453 server.on('error', (err: NodeJS.ErrnoException) => {
454 if (err.code === 'EADDRINUSE') {
455 console.error(
456 colors.red(`Port ${options.port} is already in use. Please choose a different port using -p option.`),
457 );
458 } else {
459 throw new CliError(`Failed to start the server: ${err.message}`);
460 }
461 process.exit(1);
462 });
463
464 // Graceful shutdown
465 process.on('SIGTERM', async () => {
466 server.close(() => {
467 console.log('\nZenStack proxy server closed');
468 });
469
470 await client.$disconnect();
471 process.exit(0);
472 });
473
474 process.on('SIGINT', async () => {
475 server.close(() => {
476 console.log('\nZenStack proxy server closed');
477 });
478 await client.$disconnect();
479 process.exit(0);
480 });
481}

Callers 1

runFunction · 0.85

Calls 3

createProxyAppFunction · 0.85
$disconnectMethod · 0.80
logMethod · 0.65

Tested by

no test coverage detected