Skip to content

Commit 6798b4d

Browse files
rsbhclaude
andcommitted
fix: chronicle start runs Nitro production server instead of Vite preview
Replace Vite preview() with spawning node .output/server/index.mjs for proper SSR, API routes, and search in production. Checks build exists, forwards signals to child process. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eef9f1e commit 6798b4d

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

  • packages/chronicle/src/cli/commands
Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
1+
import { existsSync } from 'node:fs';
2+
import path from 'node:path';
3+
import { spawn } from 'node:child_process';
14
import chalk from 'chalk';
25
import { Command } from 'commander';
36
import { loadCLIConfig } from '@/cli/utils/config';
4-
import { PACKAGE_ROOT } from '@/cli/utils/resolve';
5-
import { linkContent } from '@/cli/utils/scaffold';
67

78
export const startCommand = new Command('start')
89
.description('Start production server')
910
.option('-p, --port <port>', 'Port number', '3000')
1011
.option('--config <path>', 'Path to chronicle.yaml')
11-
.option('--host <host>', 'Host address', 'localhost')
12+
.option('--host <host>', 'Host address', '0.0.0.0')
1213
.action(async options => {
13-
const { config, projectRoot, configPath } = await loadCLIConfig(options.config);
14-
const port = parseInt(options.port, 10);
15-
await linkContent(projectRoot, config);
14+
const { projectRoot } = await loadCLIConfig(options.config);
15+
const serverEntry = path.resolve(projectRoot, '.output/server/index.mjs');
1616

17-
console.log(chalk.cyan('Starting production server...'));
17+
if (!existsSync(serverEntry)) {
18+
console.error(chalk.red('No build found. Run `chronicle build` first.'));
19+
process.exit(1);
20+
}
1821

19-
const { preview } = await import('vite');
20-
const { createViteConfig } = await import('@/server/vite-config');
22+
console.log(chalk.cyan('Starting production server...'));
2123

22-
const viteConfig = await createViteConfig({ packageRoot: PACKAGE_ROOT, projectRoot, configPath });
23-
const server = await preview({
24-
...viteConfig,
25-
preview: { port, host: options.host }
24+
const child = spawn(process.execPath, [serverEntry], {
25+
stdio: 'inherit',
26+
env: {
27+
...process.env,
28+
PORT: options.port,
29+
HOST: options.host,
30+
},
2631
});
2732

28-
server.printUrls();
33+
const shutdown = () => {
34+
child.kill('SIGTERM');
35+
};
36+
process.once('SIGINT', shutdown);
37+
process.once('SIGTERM', shutdown);
38+
39+
child.on('exit', (code) => {
40+
process.exit(code ?? 0);
41+
});
2942
});

0 commit comments

Comments
 (0)