nervepay 1.5.9 → 1.6.0
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/bin/nervepay-cli.js +35 -0
- package/package.json +1 -1
package/bin/nervepay-cli.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { readFile, writeFile, mkdir } from 'fs/promises';
|
|
8
8
|
import { existsSync } from 'fs';
|
|
9
|
+
import { execSync } from 'child_process';
|
|
9
10
|
import { homedir, networkInterfaces } from 'os';
|
|
10
11
|
import { join, dirname } from 'path';
|
|
11
12
|
import { fileURLToPath } from 'url';
|
|
@@ -190,6 +191,31 @@ function formatHostForUrl(host) {
|
|
|
190
191
|
return host.includes(':') ? `[${host}]` : host;
|
|
191
192
|
}
|
|
192
193
|
|
|
194
|
+
function detectTailscaleHostname() {
|
|
195
|
+
try {
|
|
196
|
+
const result = execSync('tailscale status --json', { timeout: 3000, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
197
|
+
const status = JSON.parse(result.toString());
|
|
198
|
+
const dnsName = status?.Self?.DNSName;
|
|
199
|
+
if (typeof dnsName === 'string' && dnsName.length > 0) {
|
|
200
|
+
return dnsName.replace(/\.$/, '');
|
|
201
|
+
}
|
|
202
|
+
} catch {
|
|
203
|
+
// Tailscale not installed or not running
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function detectPublicIp() {
|
|
209
|
+
try {
|
|
210
|
+
const result = execSync('curl -sf --max-time 3 https://api.ipify.org?format=text', { timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
211
|
+
const ip = result.toString().trim();
|
|
212
|
+
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(ip)) return ip;
|
|
213
|
+
} catch {
|
|
214
|
+
// No internet or service unavailable
|
|
215
|
+
}
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
|
|
193
219
|
function detectServerIp() {
|
|
194
220
|
const envIp =
|
|
195
221
|
process.env.OPENCLAW_PUBLIC_IP ||
|
|
@@ -197,6 +223,15 @@ function detectServerIp() {
|
|
|
197
223
|
process.env.NERVEPAY_PUBLIC_IP;
|
|
198
224
|
if (envIp && envIp.trim()) return envIp.trim();
|
|
199
225
|
|
|
226
|
+
// Try Tailscale MagicDNS hostname (routable across tailnet)
|
|
227
|
+
const tailscaleHost = detectTailscaleHostname();
|
|
228
|
+
if (tailscaleHost) return tailscaleHost;
|
|
229
|
+
|
|
230
|
+
// Try external public IP (handles cloud VMs behind NAT)
|
|
231
|
+
const publicIp = detectPublicIp();
|
|
232
|
+
if (publicIp) return publicIp;
|
|
233
|
+
|
|
234
|
+
// Fallback: scan network interfaces
|
|
200
235
|
const ifaces = networkInterfaces();
|
|
201
236
|
const publicIpv4 = [];
|
|
202
237
|
const privateIpv4 = [];
|