Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

feat(desktop): LAN access toggle to bind server on 0.0.0.0 (#442, #418) (#447)

Tashfeen68aef9692ae8
diff --git a/desktop/src/config.ts b/desktop/src/config.ts
index df504161..7baac874 100644
--- a/desktop/src/config.ts
+++ b/desktop/src/config.ts
@@ -7,6 +7,10 @@ export interface DesktopConfig {
theme?: 'dark' | 'light';
// BCP-47 locale mirrored from the dashboard (en, zh-CN, fr, es, pt-BR).
locale?: string;
+ // Bind the embedded server to 0.0.0.0 instead of 127.0.0.1 so other devices
+ // on the LAN / Tailscale can reach it (#442, #418). Off by default: exposes
+ // the API, guarded only by the unified key. Applied at next server start.
+ lanAccess?: boolean;
}
function configPath(): string {
diff --git a/desktop/src/i18n.ts b/desktop/src/i18n.ts
index 3b73ddde..14a6f372 100644
--- a/desktop/src/i18n.ts
+++ b/desktop/src/i18n.ts
@@ -28,6 +28,7 @@ const STRINGS: Record<NativeLocale, Strings> = {
tooltip: 'FreeLLMAPI — local LLM router',
runningOn: 'Running on {addr}',
openDashboard: 'Open Dashboard',
+ lanAccess: 'Allow LAN access (0.0.0.0)',
quitApp: 'Quit FreeLLMAPI',
running: 'running',
requestsToday: 'Requests today',
@@ -47,6 +48,7 @@ const STRINGS: Record<NativeLocale, Strings> = {
tooltip: 'FreeLLMAPI — 本地 LLM 路由器',
runningOn: '运行于 {addr}',
openDashboard: '打开仪表板',
+ lanAccess: '允许局域网访问 (0.0.0.0)',
quitApp: '退出 FreeLLMAPI',
running: '运行中',
requestsToday: '今日请求',
@@ -66,6 +68,7 @@ const STRINGS: Record<NativeLocale, Strings> = {
tooltip: 'FreeLLMAPI — routeur LLM local',
runningOn: 'En cours sur {addr}',
openDashboard: 'Ouvrir le tableau de bord',
+ lanAccess: 'Autoriser l\'accès LAN (0.0.0.0)',
quitApp: 'Quitter FreeLLMAPI',
running: 'en cours',
requestsToday: "Requêtes aujourd'hui",
@@ -85,6 +88,7 @@ const STRINGS: Record<NativeLocale, Strings> = {
tooltip: 'FreeLLMAPI — enrutador LLM local',
runningOn: 'En ejecución en {addr}',
openDashboard: 'Abrir el panel',
+ lanAccess: 'Permitir acceso LAN (0.0.0.0)',
quitApp: 'Salir de FreeLLMAPI',
running: 'en ejecución',
requestsToday: 'Solicitudes hoy',
@@ -104,6 +108,7 @@ const STRINGS: Record<NativeLocale, Strings> = {
tooltip: 'FreeLLMAPI — roteador LLM local',
runningOn: 'Em execução em {addr}',
openDashboard: 'Abrir o painel',
+ lanAccess: 'Permitir acesso LAN (0.0.0.0)',
quitApp: 'Sair do FreeLLMAPI',
running: 'em execução',
requestsToday: 'Solicitações hoje',
@@ -123,6 +128,7 @@ const STRINGS: Record<NativeLocale, Strings> = {
tooltip: 'FreeLLMAPI — router LLM locale',
runningOn: 'In esecuzione su {addr}',
openDashboard: 'Apri il pannello',
+ lanAccess: 'Consenti accesso LAN (0.0.0.0)',
quitApp: 'Esci da FreeLLMAPI',
running: 'in esecuzione',
requestsToday: 'Richieste oggi',
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index 29e0628c..5ea86a88 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -115,6 +115,34 @@ if (!app.requestSingleInstanceLock()) {
ipcMain.handle('freeapi:set-login-item', (_e, open: boolean) => app.setLoginItemSettings({ openAtLogin: open }));
ipcMain.handle('freeapi:quit', () => app.quit());
+ // Flip the LAN-access flag and relaunch so the server rebinds (127.0.0.1 ↔
+ // 0.0.0.0). Enabling shows a one-time warning: the API becomes reachable by
+ // anything that can route to this machine, guarded only by the unified key.
+ async function toggleLanAccess(): Promise<void> {
+ const current = loadConfig().lanAccess ?? false;
+ const enabling = !current;
+ if (enabling) {
+ const { response } = await dialog.showMessageBox({
+ type: 'warning',
+ buttons: ['Enable LAN access', 'Cancel'],
+ defaultId: 1,
+ cancelId: 1,
+ title: 'Allow LAN access',
+ message: 'Expose FreeLLMAPI to your local network?',
+ detail:
+ 'The server will bind to 0.0.0.0 so other devices (Tailscale, VMs, ' +
+ 'phones on your Wi-Fi) can reach it at http://<this-machine-ip>:' +
+ `${resolvedPort}/v1.\n\nThe API is protected only by your unified ` +
+ 'API key. Only do this on a network you trust. The app will restart ' +
+ 'to apply the change.',
+ });
+ if (response !== 0) return;
+ }
+ saveConfig({ ...loadConfig(), lanAccess: enabling });
+ app.relaunch();
+ app.quit();
+ }
+
app.whenReady().then(async () => {
if (process.platform === 'darwin') app.dock?.hide();
@@ -128,18 +156,24 @@ if (!app.requestSingleInstanceLock()) {
? path.join(process.resourcesPath, 'client-dist')
: path.join(repoRoot, 'client/dist');
+ // LAN access binds the embedded server to 0.0.0.0 so Tailscale / VMs / other
+ // devices can reach it (#442, #418). Off by default — 127.0.0.1 keeps the
+ // API local-only. The bind host is fixed at listen() time, so the tray
+ // toggle persists the flag and relaunches.
+ const host = cfg.lanAccess ? '0.0.0.0' : '127.0.0.1';
+
try {
const { port } = await startServer({
dbPath,
clientDist,
- host: '127.0.0.1',
+ host,
preferredPort: cfg.port ?? DEFAULT_PORT,
});
resolvedPort = port;
saveConfig({ ...cfg, port });
sessionToken = ensureSessionToken();
- const tray = buildTray(port, sessionToken, () => locale);
- console.log(`[desktop] FreeLLMAPI running on http://127.0.0.1:${port}`);
+ const tray = buildTray(port, sessionToken, () => locale, () => loadConfig().lanAccess ?? false, toggleLanAccess);
+ console.log(`[desktop] FreeLLMAPI running on http://${host}:${port}${cfg.lanAccess ? ' (LAN access enabled)' : ''}`);
// Dev-only UI verification: FREEAPI_SHOT=1 opens the popover and the
// dashboard, captures both to /tmp, and quits. FREEAPI_SHOT=hold opens
diff --git a/desktop/src/tray.ts b/desktop/src/tray.ts
index 9f3ab09d..ae95c54e 100644
--- a/desktop/src/tray.ts
+++ b/desktop/src/tray.ts
@@ -14,7 +14,13 @@ let tray: Tray | null = null;
// is rebuilt on every right-click, so reading the live locale via getLocale()
// keeps its labels current after a language switch; the static tooltip is
// refreshed separately (refreshTrayLocale).
-export function buildTray(port: number, token: string, getLocale: () => NativeLocale): Tray {
+export function buildTray(
+ port: number,
+ token: string,
+ getLocale: () => NativeLocale,
+ getLanAccess: () => boolean,
+ onToggleLanAccess: () => void,
+): Tray {
const iconPath = path.join(__dirname, '../assets/trayTemplate.png');
const icon = nativeImage.createFromPath(iconPath);
icon.setTemplateImage(true); // auto light/dark tint in the macOS menu bar
@@ -25,10 +31,14 @@ export function buildTray(port: number, token: string, getLocale: () => NativeLo
tray.on('click', () => togglePopover(tray!));
tray.on('right-click', () => {
const locale = getLocale();
+ const lanOn = getLanAccess();
tray!.popUpContextMenu(Menu.buildFromTemplate([
- { label: dt(locale, 'runningOn', { addr: `127.0.0.1:${port}` }), enabled: false },
+ { label: dt(locale, 'runningOn', { addr: `${lanOn ? '0.0.0.0' : '127.0.0.1'}:${port}` }), enabled: false },
{ label: dt(locale, 'openDashboard'), click: () => openDashboard(port, token) },
{ type: 'separator' },
+ // Toggling relaunches the app (the bind host is fixed at server start).
+ { label: dt(locale, 'lanAccess'), type: 'checkbox', checked: lanOn, click: () => onToggleLanAccess() },
+ { type: 'separator' },
{ label: dt(locale, 'quitApp'), click: () => app.quit() },
]));
});