renote-server 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.js CHANGED
@@ -4,13 +4,36 @@ exports.CONFIG = void 0;
4
4
  const dotenv_1 = require("dotenv");
5
5
  const os_1 = require("os");
6
6
  (0, dotenv_1.config)();
7
+ /**
8
+ * Parse CLI arguments: --port, --host, --token, --claude-home
9
+ * These take precedence over environment variables.
10
+ */
11
+ function parseArgs() {
12
+ const args = {};
13
+ const argv = process.argv.slice(2);
14
+ for (let i = 0; i < argv.length; i++) {
15
+ const arg = argv[i];
16
+ if (arg.startsWith('--') && i + 1 < argv.length && !argv[i + 1].startsWith('--')) {
17
+ const key = arg.slice(2);
18
+ args[key] = argv[i + 1];
19
+ i++;
20
+ }
21
+ else if (arg.startsWith('--') && arg.includes('=')) {
22
+ const [key, value] = arg.slice(2).split('=');
23
+ args[key] = value;
24
+ }
25
+ }
26
+ return args;
27
+ }
28
+ const args = parseArgs();
7
29
  exports.CONFIG = {
8
- port: parseInt(process.env.PORT || '8080'),
9
- authToken: process.env.AUTH_TOKEN || '',
10
- claudeHome: process.env.CLAUDE_HOME || `${(0, os_1.homedir)()}/.claude`,
30
+ host: args['host'] || process.env.HOST || '0.0.0.0',
31
+ port: parseInt(args['port'] || process.env.PORT || '9080'),
32
+ authToken: args['token'] || process.env.AUTH_TOKEN || '',
33
+ claudeHome: args['claude-home'] || process.env.CLAUDE_HOME || `${(0, os_1.homedir)()}/.claude`,
11
34
  maxFileSize: parseInt(process.env.MAX_FILE_SIZE || '10485760'),
12
35
  searchTimeout: parseInt(process.env.SEARCH_TIMEOUT || '5000'),
13
- logLevel: process.env.LOG_LEVEL || 'info',
36
+ logLevel: args['log-level'] || process.env.LOG_LEVEL || 'info',
14
37
  };
15
38
  if (!exports.CONFIG.authToken) {
16
39
  console.warn('WARNING: AUTH_TOKEN not set. Generate: openssl rand -hex 32');
@@ -21,8 +21,8 @@ function createHttpServer() {
21
21
  res.json({ token: config_1.CONFIG.authToken });
22
22
  });
23
23
  const httpPort = config_1.CONFIG.port + 1;
24
- app.listen(httpPort, () => {
25
- logger_1.logger.info(`HTTP server running on port ${httpPort}`);
24
+ app.listen(httpPort, config_1.CONFIG.host, () => {
25
+ logger_1.logger.info(`HTTP server running on ${config_1.CONFIG.host}:${httpPort}`);
26
26
  });
27
27
  return app;
28
28
  }
package/dist/index.js CHANGED
File without changes
@@ -27,51 +27,60 @@ class WebSocketServer {
27
27
  this.gitHandler = new git_1.GitHandler(this.send.bind(this));
28
28
  // Handle HTTP upgrade requests
29
29
  server.on('upgrade', (request, socket, head) => {
30
+ const clientIp = request.socket.remoteAddress;
31
+ const clientPort = request.socket.remotePort;
32
+ logger_1.logger.info(`[WS Upgrade] Request from ${clientIp}:${clientPort}, URL: ${request.url}`);
30
33
  // Route /terminal to terminal direct WebSocket handler
31
34
  if (terminalWebSocket_1.terminalWebSocketHandler.shouldHandle(request)) {
35
+ logger_1.logger.info(`[WS Upgrade] Routing to terminal handler`);
32
36
  const terminalWss = new ws_1.default.Server({ noServer: true });
33
37
  terminalWss.handleUpgrade(request, socket, head, (ws) => {
38
+ logger_1.logger.info(`[WS Upgrade] Terminal upgrade complete`);
34
39
  terminalWebSocket_1.terminalWebSocketHandler.handleConnection(ws, request);
35
40
  });
36
41
  }
37
42
  else {
38
43
  // Default: main WebSocket for JSON-RPC style messages
44
+ logger_1.logger.info(`[WS Upgrade] Routing to main handler`);
39
45
  this.wss.handleUpgrade(request, socket, head, (ws) => {
46
+ logger_1.logger.info(`[WS Upgrade] Main upgrade complete`);
40
47
  this.wss.emit('connection', ws, request);
41
48
  });
42
49
  }
43
50
  });
44
51
  this.setupWebSocket();
45
- server.listen(config_1.CONFIG.port, () => {
46
- logger_1.logger.info(`WebSocket server running on port ${config_1.CONFIG.port}`);
47
- logger_1.logger.info(` - Main API: ws://host:${config_1.CONFIG.port}/`);
48
- logger_1.logger.info(` - Terminal direct: ws://host:${config_1.CONFIG.port}/terminal`);
52
+ server.listen(config_1.CONFIG.port, config_1.CONFIG.host, () => {
53
+ logger_1.logger.info(`WebSocket server running on ${config_1.CONFIG.host}:${config_1.CONFIG.port}`);
54
+ logger_1.logger.info(` - Main API: ws://${config_1.CONFIG.host}:${config_1.CONFIG.port}/`);
55
+ logger_1.logger.info(` - Terminal direct: ws://${config_1.CONFIG.host}:${config_1.CONFIG.port}/terminal`);
49
56
  });
50
57
  }
51
58
  setupWebSocket() {
52
- this.wss.on('connection', (ws) => {
53
- logger_1.logger.info('New client connection attempt');
59
+ this.wss.on('connection', (ws, request) => {
60
+ const clientIp = request?.socket?.remoteAddress || 'unknown';
61
+ logger_1.logger.info(`[WS Connection] New client from ${clientIp}`);
54
62
  ws.on('message', async (data) => {
55
63
  try {
56
64
  const message = JSON.parse(data.toString());
65
+ logger_1.logger.info(`[WS Message] Type: ${message.type}, from ${clientIp}`);
57
66
  await this.handleMessage(ws, message);
58
67
  }
59
68
  catch (error) {
60
- logger_1.logger.error('Error parsing message:', error);
69
+ logger_1.logger.error(`[WS Message] Parse error from ${clientIp}:`, error);
61
70
  this.sendError(ws, 'Invalid message format');
62
71
  }
63
72
  });
64
- ws.on('close', () => {
73
+ ws.on('close', (code, reason) => {
65
74
  const clientId = this.getClientId(ws);
75
+ logger_1.logger.info(`[WS Close] Client ${clientId || 'unknown'} closed with code ${code}, reason: ${reason?.toString() || 'none'}`);
66
76
  if (clientId) {
67
77
  this.terminalHandler.cleanup(clientId);
68
78
  (0, sessionBrowser_1.unwatchSession)(clientId);
69
79
  this.clients.delete(clientId);
70
- logger_1.logger.info(`Client ${clientId} disconnected`);
71
80
  }
72
81
  });
73
82
  ws.on('error', (error) => {
74
- logger_1.logger.error('WebSocket error:', error);
83
+ logger_1.logger.error('[WS Error]:', error);
75
84
  });
76
85
  });
77
86
  }
@@ -466,6 +475,7 @@ class WebSocketServer {
466
475
  }
467
476
  }
468
477
  async handleAuth(ws, token) {
478
+ logger_1.logger.info(`[Auth] Validating token: "${token ? '***' : '(empty)'}"`);
469
479
  if (this.authManager.validateToken(token)) {
470
480
  const clientId = this.authManager.generateClientId();
471
481
  this.clients.set(clientId, ws);
@@ -474,9 +484,10 @@ class WebSocketServer {
474
484
  type: 'auth_success',
475
485
  data: { clientId }
476
486
  });
477
- logger_1.logger.info(`Client ${clientId} authenticated`);
487
+ logger_1.logger.info(`[Auth] Client ${clientId} authenticated successfully`);
478
488
  }
479
489
  else {
490
+ logger_1.logger.warn(`[Auth] Invalid token rejected`);
480
491
  this.sendError(ws, 'Invalid token');
481
492
  ws.close();
482
493
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "renote-server",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "WebSocket server for Renote - mobile remote development client with Claude Code integration",
5
5
  "main": "dist/index.js",
6
6
  "bin": {