@@ -20,9 +20,25 @@ const EventEmitter = require('bare-events');
|
||||
const { allocateTunnelPort, releaseTunnelPort } = require('./holesail-manager/port-allocator.js');
|
||||
|
||||
// Resolve the extension/dashboard directory for dev-mode file serving.
|
||||
// In dev mode, __dirname is native-host/ so the dashboard is one level up.
|
||||
// In distribution mode this path is never used (files come from the bundle).
|
||||
const DEV_DASHBOARD_DIR = path.join(__dirname, '..', 'extension', 'dashboard');
|
||||
// Uses the same logic as host/paths.js: in dev mode __dirname is the real
|
||||
// native-host/ directory; in distribution mode the bundle read takes priority
|
||||
// and this path is only used as a last-resort fallback.
|
||||
function _resolveDevDashboardDir() {
|
||||
// In dev mode __dirname is the real native-host/ path
|
||||
if (__dirname && !__dirname.startsWith('bare:')) {
|
||||
return path.join(__dirname, '..', 'extension', 'dashboard');
|
||||
}
|
||||
// Distribution mode: try executable directory as fallback
|
||||
try {
|
||||
const os = require('bare-os');
|
||||
const execPath = os.execPath();
|
||||
if (execPath && !execPath.startsWith('bare:')) {
|
||||
return path.join(path.dirname(execPath), 'extension', 'dashboard');
|
||||
}
|
||||
} catch (_) {}
|
||||
return null;
|
||||
}
|
||||
const DEV_DASHBOARD_DIR = _resolveDevDashboardDir();
|
||||
|
||||
const DASHBOARD_HOSTNAME = 'my.dash.board';
|
||||
|
||||
@@ -67,12 +83,14 @@ function _readFileByKey(bundleKey, diskRelPath) {
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
// Development mode: read from disk
|
||||
// Disk fallback (dev mode, or distribution mode without bundle assets)
|
||||
if (DEV_DASHBOARD_DIR) {
|
||||
try {
|
||||
const fs = require('bare-fs');
|
||||
const fullPath = path.join(DEV_DASHBOARD_DIR, diskRelPath);
|
||||
return fs.readFileSync(fullPath);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import 'bare-process/global';
|
||||
import { createRequire } from 'bare-module';
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
// Simulate: startup.js (in host/) requires dashboard-server.js (in native-host/)
|
||||
const startup_require = createRequire(new URL('./host/startup.js', import.meta.url));
|
||||
const dashServer = startup_require('../dashboard-server.js');
|
||||
console.log('dashServer.getHostname():', dashServer.getHostname());
|
||||
const result = await dashServer.start();
|
||||
console.log('start result:', result);
|
||||
await dashServer.stop();
|
||||
@@ -0,0 +1,11 @@
|
||||
const path = require('bare-path');
|
||||
console.log('__dirname:', __dirname);
|
||||
const DEV_DASHBOARD_DIR = path.join(__dirname, '..', 'extension', 'dashboard');
|
||||
console.log('DEV_DASHBOARD_DIR:', DEV_DASHBOARD_DIR);
|
||||
const fs = require('bare-fs');
|
||||
try {
|
||||
const f = fs.readFileSync(path.join(DEV_DASHBOARD_DIR, 'dashboard.html'));
|
||||
console.log('READ OK, size:', f.length);
|
||||
} catch(e) {
|
||||
console.log('READ FAILED:', e.message);
|
||||
}
|
||||
Reference in New Issue
Block a user