Add embedded Express admin API and unified dev workflow.
Move admin backend into this repo (Express + MySQL on :8085) so npm run dev starts both API and Vite, with updated env defaults and Caddy config for gadm.tkmind.cn. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import path from 'node:path';
|
||||
import { createDbPool, isDatabaseConfigured } from './db.mjs';
|
||||
import { importMemind, resolveMemindLib } from './lib-path.mjs';
|
||||
import { projectRoot } from './load-env.mjs';
|
||||
|
||||
export async function bootstrapAdminServices() {
|
||||
if (!isDatabaseConfigured()) {
|
||||
throw new Error('数据库未配置');
|
||||
}
|
||||
|
||||
const memindLib = resolveMemindLib();
|
||||
const pool = createDbPool();
|
||||
const { createUserAuth } = await importMemind('user-auth.mjs');
|
||||
const { createLlmProviderService } = await importMemind('llm-providers.mjs');
|
||||
|
||||
const usersRoot =
|
||||
process.env.H5_USERS_ROOT?.trim() ?? path.join(projectRoot, 'data', 'users');
|
||||
const apiTarget = process.env.TKMIND_API_TARGET ?? 'https://127.0.0.1:18006';
|
||||
const apiSecret = process.env.TKMIND_SERVER__SECRET_KEY ?? 'local-dev-secret';
|
||||
|
||||
const userAuth = createUserAuth(pool, {
|
||||
usersRoot,
|
||||
h5Root: memindLib,
|
||||
defaultSignupBalanceCents: Number(process.env.H5_SIGNUP_BALANCE_CENTS ?? 500),
|
||||
});
|
||||
|
||||
await userAuth.ensureAdminUser();
|
||||
|
||||
const llmProviderService = createLlmProviderService(pool, {
|
||||
apiTarget,
|
||||
apiSecret,
|
||||
});
|
||||
|
||||
console.log(`Admin DB connected (${process.env.MYSQL_DATABASE ?? 'via DATABASE_URL'})`);
|
||||
console.log(`Users root: ${usersRoot}`);
|
||||
console.log(`Memind lib: ${memindLib}`);
|
||||
|
||||
return { pool, userAuth, llmProviderService };
|
||||
}
|
||||
Reference in New Issue
Block a user