diff --git a/app/src/App.ts b/app/src/App.ts index 3beec46..0d8f873 100644 --- a/app/src/App.ts +++ b/app/src/App.ts @@ -106,8 +106,6 @@ export class App { await this.emgr.emit(new AppBuiltEvent({ app: this })); - server.all("/api/*", async (c) => c.notFound()); - // first boot is set from ModuleManager when there wasn't a config table if (this.trigger_first_boot) { this.trigger_first_boot = false; diff --git a/app/src/cli/commands/debug.ts b/app/src/cli/commands/debug.ts index 124d7d2..77a668c 100644 --- a/app/src/cli/commands/debug.ts +++ b/app/src/cli/commands/debug.ts @@ -1,20 +1,45 @@ import path from "node:path"; import url from "node:url"; +import { createApp } from "App"; +import { getConnectionCredentialsFromEnv } from "cli/commands/run/platform"; import { getDistPath, getRelativeDistPath, getRootPath } from "cli/utils/sys"; +import { Argument } from "commander"; +import { showRoutes } from "hono/dev"; import type { CliCommand } from "../types"; export const debug: CliCommand = (program) => { program .command("debug") - .description("debug path resolution") - .action(() => { - console.log("paths", { - rootpath: getRootPath(), - distPath: getDistPath(), - relativeDistPath: getRelativeDistPath(), - cwd: process.cwd(), - dir: path.dirname(url.fileURLToPath(import.meta.url)), - resolvedPkg: path.resolve(getRootPath(), "package.json") - }); - }); + .description("debug bknd") + .addArgument(new Argument("", "subject to debug").choices(Object.keys(subjects))) + .action(action); }; + +const subjects = { + paths: async () => { + console.log("[PATHS]", { + rootpath: getRootPath(), + distPath: getDistPath(), + relativeDistPath: getRelativeDistPath(), + cwd: process.cwd(), + dir: path.dirname(url.fileURLToPath(import.meta.url)), + resolvedPkg: path.resolve(getRootPath(), "package.json") + }); + }, + routes: async () => { + console.log("[APP ROUTES]"); + const credentials = getConnectionCredentialsFromEnv(); + const app = createApp({ connection: credentials }); + await app.build(); + showRoutes(app.server); + } +}; + +async function action(subject: string) { + console.log("debug", { subject }); + if (subject in subjects) { + await subjects[subject](); + } else { + console.error("Invalid subject: ", subject); + } +} diff --git a/app/src/flows/AppFlows.ts b/app/src/flows/AppFlows.ts index 4f75cbf..c31e051 100644 --- a/app/src/flows/AppFlows.ts +++ b/app/src/flows/AppFlows.ts @@ -63,6 +63,8 @@ export class AppFlows extends Module { }); }); + hono.all("*", (c) => c.notFound()); + this.ctx.server.route(this.config.basepath, hono); // register flows diff --git a/app/vite.dev.ts b/app/vite.dev.ts index 9dfb3a1..cf95359 100644 --- a/app/vite.dev.ts +++ b/app/vite.dev.ts @@ -1,5 +1,6 @@ import { readFile } from "node:fs/promises"; import { serveStatic } from "@hono/node-server/serve-static"; +import { showRoutes } from "hono/dev"; import { App, registries } from "./src"; import { StorageLocalAdapter } from "./src/media/storage/adapters/StorageLocalAdapter"; @@ -28,6 +29,7 @@ if (example) { let app: App; const recreate = import.meta.env.VITE_APP_DISABLE_FRESH !== "1"; +let routesShown = false; export default { async fetch(request: Request) { if (!app || recreate) { @@ -44,6 +46,14 @@ export default { "sync" ); await app.build(); + + // log routes + if (!routesShown) { + routesShown = true; + console.log("\n\n[APP ROUTES]"); + showRoutes(app.server); + console.log("-------\n\n"); + } } return app.fetch(request);