mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-14 03:30:19 +00:00
30835b27d2
Ports PR #14800's standalone Hono dev runtime onto the new apps/server package. bun run dev:hono-lite boots Hono on :3011 + Vite on :9876 with NO Next.js process, serving the full near-parity API surface: /trpc/* - lambda / mobile / tools / async TRPC routers /webapi/* - chat, models, createImage, speech, trace /market/* - agent / model / plugin market /oidc/* - OIDC provider /f/* - fileProxy + userAvatar /api/* - auth, webhooks, dev, v1, memory (catch-all, registered last) Better Auth's /api/auth/* and dev-local-login flow run end-to-end; authenticated tRPC queries return real user data. bun run dev (Next) stays unbroken. Squashed from 11 commits ported from the original branch: - L0 core: runtime-neutral scheduleAfterResponse (drop next/server from apps/server), tRPC runtime handlers + Hono /trpc sub-app, standalone Hono root app + Node entry, dev:hono-lite topology (devHonoLite.mts + devTopology.ts + viteNodeServer.config.ts), Better Auth dev-local-login bootstrap, @lobehub/editor dedupe - L1 webapi: chat, models, createImage, speech, trace - L2 misc: market, oidc, fileProxy, userAvatar - L3 agent + api catch-all: agentStream, agentEvalRunWorkflow, agent-hono / workflows-hono mounts, api-hono catch-all Dev ergonomics: - vite-node@3.2.4 as a workspace devDep (was bunx-fetched per-run) - npx vite-node instead of bunx vite-node@3.2.4 in dev:hono:server - unified process.title across dev nodes: lobe-dev, lobe-dev-hono-lite, lobe-dev-hono-${port}, lobe-dev-vite-${platform}, lobe-dev-login - fix lobe-dev-proxy-print plugin swallowing Vite's Local/Network URLs in printUrls; now: Local + Network + Hono API + Debug Proxy Docs: apps/server/README.md (routes, ports, dev-login gate, known gaps, troubleshooting); docs/development/start.mdx EN/zh-CN section. Tier T1 (dev-runnable only): gray-release machinery, production- deployable apps/server (T2/T3), and a handful of post-#14800 routes (oauth/connector/callback, api/dev/test-push, webapi/revalidate, agent-eval-run extras) are intentionally out of scope.
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { spawn } from 'node:child_process';
|
|
|
|
import dotenv from 'dotenv';
|
|
|
|
import devTopology from './devTopology';
|
|
|
|
const { applyDefaultDevTopologyEnv } = devTopology;
|
|
|
|
dotenv.config();
|
|
process.env.LOBE_DEV_TOPOLOGY ||= 'hono-lite';
|
|
|
|
const devTopologyConfig = applyDefaultDevTopologyEnv(process.env);
|
|
process.title = 'lobe-dev-login';
|
|
|
|
const readArg = (name: string) => {
|
|
const index = process.argv.indexOf(name);
|
|
|
|
return index === -1 ? undefined : process.argv[index + 1];
|
|
};
|
|
|
|
const resolveBrowserOpenCommand = (url: string) => {
|
|
if (process.platform === 'win32') {
|
|
return { args: ['url.dll,FileProtocolHandler', url], cmd: 'rundll32' };
|
|
}
|
|
|
|
return {
|
|
args: [url],
|
|
cmd: process.platform === 'darwin' ? 'open' : 'xdg-open',
|
|
};
|
|
};
|
|
|
|
const openBrowser = (url: string) => {
|
|
const command = resolveBrowserOpenCommand(url);
|
|
const child = spawn(command.cmd, command.args, {
|
|
detached: true,
|
|
stdio: 'ignore',
|
|
shell: process.platform === 'win32',
|
|
});
|
|
|
|
child.once('error', (error) => {
|
|
console.error(`Failed to open browser: ${error.message}`);
|
|
console.error(url);
|
|
});
|
|
child.unref();
|
|
};
|
|
|
|
const email = readArg('--email') || process.env.LOBE_DEV_LOGIN_EMAIL || 'dev@local.test';
|
|
const name = readArg('--name') || process.env.LOBE_DEV_LOGIN_NAME || 'Local Dev';
|
|
const callbackURL = readArg('--callback') || '/';
|
|
const url = new URL('/api/auth/dev/local-login', devTopologyConfig.appUrl);
|
|
|
|
url.searchParams.set('email', email);
|
|
url.searchParams.set('name', name);
|
|
url.searchParams.set('callbackURL', callbackURL);
|
|
|
|
console.log(`Opening local dev login URL: ${url.toString()}`);
|
|
openBrowser(url.toString());
|