-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathnode.ts
More file actions
57 lines (48 loc) · 1.77 KB
/
node.ts
File metadata and controls
57 lines (48 loc) · 1.77 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
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
/**
* Node.js-specific entry point
*
* This module handles Node.js-specific initialization including CLI argument parsing,
* Claude CLI validation, and server startup using the NodeRuntime.
*/
import { createApp } from "../app.ts";
import { NodeRuntime } from "../runtime/node.ts";
import { parseCliArgs } from "./args.ts";
import { validateClaudeCli } from "./validation.ts";
import { setupLogger, logger } from "../utils/logger.ts";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { exit } from "../utils/os.ts";
async function main(runtime: NodeRuntime) {
// Parse CLI arguments
const args = parseCliArgs();
// Initialize logging system
await setupLogger(args.debug);
if (args.debug) {
logger.cli.info("🐛 Debug mode enabled");
}
// Validate Claude CLI availability and get the detected CLI path
const cliPath = await validateClaudeCli(runtime, args.claudePath);
// Use absolute path for static files (supported in @hono/node-server v1.17.0+)
// Node.js 20.11.0+ compatible with fallback for older versions
const __dirname =
import.meta.dirname ?? dirname(fileURLToPath(import.meta.url));
const staticPath = join(__dirname, "../static");
// Create application
const app = createApp(runtime, {
debugMode: args.debug,
staticPath,
cliPath,
claudeArgs: args.claudeArgs,
});
// Start server (only show this message when everything is ready)
logger.cli.info(`🚀 Server starting on ${args.host}:${args.port}`);
runtime.serve(args.port, args.host, app.fetch);
}
// Run the application
const runtime = new NodeRuntime();
main(runtime).catch((error) => {
// Logger may not be initialized yet, so use console.error
console.error("Failed to start server:", error);
exit(1);
});