logmon-cli 1.0.13 → 1.0.14

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.
Files changed (2) hide show
  1. package/index.js +38 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -7,9 +7,37 @@ const os = require('os');
7
7
  const readline = require('readline');
8
8
  const pkg = require('./package.json');
9
9
 
10
+ const http = require('http');
11
+
10
12
  // 전체 인자 중 'uninstall'이 포함되어 있는지 견고하게 확인
11
13
  const isUninstall = process.argv.includes('uninstall');
12
14
 
15
+ function checkBackendHealth(url) {
16
+ return new Promise((resolve) => {
17
+ const matches = url.match(/https?:\/\/([^:/]+)(?::(\d+))?/);
18
+ if (!matches) {
19
+ resolve(false);
20
+ return;
21
+ }
22
+ const host = matches[1];
23
+ const port = matches[2] || 80;
24
+ const path = '/api/health';
25
+
26
+ const req = http.get({ host, port, path, timeout: 500 }, (res) => {
27
+ resolve(res.statusCode === 200);
28
+ });
29
+
30
+ req.on('error', () => {
31
+ resolve(false);
32
+ });
33
+
34
+ req.on('timeout', () => {
35
+ req.destroy();
36
+ resolve(false);
37
+ });
38
+ });
39
+ }
40
+
13
41
  function getSavedConfig() {
14
42
  const homeDir = os.homedir();
15
43
  const unixConfigPath = path.join(homeDir, '.logmon_agent', 'logmon_config.json');
@@ -72,18 +100,16 @@ async function run() {
72
100
  }
73
101
  backendUrl = foundUrl || process.env.BACKEND_URL || backendUrl;
74
102
 
75
- // 만약 기존 설정도 없고, 인자도 주어지지 않았고, 테스트 모드가 아닐 때 대화형 입력 받기
76
- if (!savedConfig && !foundUrl && (!firstArg || firstArg === 'uninstall') && process.env.LOGMON_TEST_MODE !== 'true') {
77
- console.log('===============================================');
78
- console.log(' ⚙️ LogMon CLI 초기 설정');
79
- console.log('===============================================');
80
- const inputUrl = await askQuestion(`백엔드 서버 주소 [${backendUrl}]: `);
81
- if (inputUrl.trim()) {
82
- backendUrl = inputUrl.trim();
83
- }
84
- const inputKey = await askQuestion(`보안 API Key [${apiKey}]: `);
85
- if (inputKey.trim()) {
86
- apiKey = inputKey.trim();
103
+ // 자동 감지(Auto-detect) 덮어쓰기 로직 (유저 타이핑 완전 제거)
104
+ if (!foundUrl && !process.env.BACKEND_URL && process.env.LOGMON_TEST_MODE !== 'true') {
105
+ const is3008Healthy = await checkBackendHealth("http://localhost:3008");
106
+ if (is3008Healthy) {
107
+ backendUrl = "http://localhost:3008/api/logmon";
108
+ } else {
109
+ const is8000Healthy = await checkBackendHealth("http://localhost:8000");
110
+ if (is8000Healthy) {
111
+ backendUrl = "http://localhost:8000/api/logmon";
112
+ }
87
113
  }
88
114
  }
89
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logmon-cli",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "LogMon Agent Auto Installer",
5
5
  "main": "index.js",
6
6
  "bin": {