mirror of
https://github.com/zadam/trilium.git
synced 2026-01-12 09:34:26 +01:00
refactor(client/lightweight): bootstrap route as part of the new router
This commit is contained in:
parent
f05fda871c
commit
c6d1457ad7
@ -42,6 +42,25 @@ function createApiRoute(router: BrowserRouter) {
|
||||
export function registerRoutes(router: BrowserRouter): void {
|
||||
const apiRoute = createApiRoute(router);
|
||||
routes.buildSharedApiRoutes(apiRoute);
|
||||
apiRoute('get', '/bootstrap', bootstrapRoute);
|
||||
}
|
||||
|
||||
function bootstrapRoute() {
|
||||
return {
|
||||
assetPath: "./",
|
||||
baseApiUrl: "../api/",
|
||||
themeCssUrl: null,
|
||||
themeUseNextAsBase: "next",
|
||||
iconPackCss: "",
|
||||
device: "desktop",
|
||||
headingStyle: "default",
|
||||
layoutOrientation: "vertical",
|
||||
platform: "web",
|
||||
isElectron: false,
|
||||
hasNativeTitleBar: false,
|
||||
hasBackgroundEffects: true,
|
||||
currentLocale: { id: "en", rtl: false }
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -135,60 +135,6 @@ function jsonResponse(obj: unknown, status = 200, extraHeaders = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
// Example: your /bootstrap handler placeholder
|
||||
async function handleBootstrap() {
|
||||
console.log("[Worker] Bootstrap request received");
|
||||
|
||||
// Try to initialize with timeout
|
||||
let dbInfo: Record<string, unknown> = { dbStatus: 'not initialized' };
|
||||
|
||||
try {
|
||||
// Wait for initialization (with timeout)
|
||||
await Promise.race([
|
||||
ensureInitialized(),
|
||||
new Promise((_, reject) => setTimeout(() => reject(new Error("Initialization timeout")), 10000))
|
||||
]);
|
||||
|
||||
// Query the database
|
||||
const stmt = sqlProvider.prepare('SELECT * FROM options');
|
||||
const rows = stmt.all() as Array<{ name: string; value: string }>;
|
||||
const options: Record<string, string> = {};
|
||||
for (const row of rows) {
|
||||
options[row.name] = row.value;
|
||||
}
|
||||
|
||||
dbInfo = {
|
||||
sqliteVersion: sqlProvider.version?.libVersion,
|
||||
optionsFromDB: options,
|
||||
dbStatus: 'connected'
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("[Worker] Error during bootstrap:", e);
|
||||
dbInfo = { dbStatus: 'error', error: String(e) };
|
||||
}
|
||||
|
||||
console.log("[Worker] Sending bootstrap response");
|
||||
|
||||
// Later: return real globals from your core state/config.
|
||||
return jsonResponse({
|
||||
assetPath: "./",
|
||||
baseApiUrl: "../api/",
|
||||
themeCssUrl: null,
|
||||
themeUseNextAsBase: "next",
|
||||
iconPackCss: "",
|
||||
device: "desktop",
|
||||
headingStyle: "default",
|
||||
layoutOrientation: "vertical",
|
||||
platform: "web",
|
||||
isElectron: false,
|
||||
hasNativeTitleBar: false,
|
||||
hasBackgroundEffects: true,
|
||||
currentLocale: { id: "en", rtl: false },
|
||||
// Add SQLite info for testing
|
||||
sqlite: dbInfo
|
||||
});
|
||||
}
|
||||
|
||||
interface LocalRequest {
|
||||
method: string;
|
||||
url: string;
|
||||
@ -201,11 +147,6 @@ async function dispatch(request: LocalRequest) {
|
||||
|
||||
console.log("[Worker] Dispatch:", url.pathname);
|
||||
|
||||
// Bootstrap is handled specially before the router is ready
|
||||
if (request.method === "GET" && url.pathname === "/bootstrap") {
|
||||
return handleBootstrap();
|
||||
}
|
||||
|
||||
// Ensure initialization is complete and get the router
|
||||
const appRouter = await ensureInitialized();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user