added deboug routes cli action

This commit is contained in:
dswbx
2025-02-18 09:25:34 +01:00
parent bd362607ae
commit e2217c411a
4 changed files with 48 additions and 13 deletions

View File

@@ -106,8 +106,6 @@ export class App {
await this.emgr.emit(new AppBuiltEvent({ app: this })); 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 // first boot is set from ModuleManager when there wasn't a config table
if (this.trigger_first_boot) { if (this.trigger_first_boot) {
this.trigger_first_boot = false; this.trigger_first_boot = false;

View File

@@ -1,14 +1,23 @@
import path from "node:path"; import path from "node:path";
import url from "node:url"; 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 { getDistPath, getRelativeDistPath, getRootPath } from "cli/utils/sys";
import { Argument } from "commander";
import { showRoutes } from "hono/dev";
import type { CliCommand } from "../types"; import type { CliCommand } from "../types";
export const debug: CliCommand = (program) => { export const debug: CliCommand = (program) => {
program program
.command("debug") .command("debug")
.description("debug path resolution") .description("debug bknd")
.action(() => { .addArgument(new Argument("<subject>", "subject to debug").choices(Object.keys(subjects)))
console.log("paths", { .action(action);
};
const subjects = {
paths: async () => {
console.log("[PATHS]", {
rootpath: getRootPath(), rootpath: getRootPath(),
distPath: getDistPath(), distPath: getDistPath(),
relativeDistPath: getRelativeDistPath(), relativeDistPath: getRelativeDistPath(),
@@ -16,5 +25,21 @@ export const debug: CliCommand = (program) => {
dir: path.dirname(url.fileURLToPath(import.meta.url)), dir: path.dirname(url.fileURLToPath(import.meta.url)),
resolvedPkg: path.resolve(getRootPath(), "package.json") 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);
}
}

View File

@@ -63,6 +63,8 @@ export class AppFlows extends Module<typeof flowsConfigSchema> {
}); });
}); });
hono.all("*", (c) => c.notFound());
this.ctx.server.route(this.config.basepath, hono); this.ctx.server.route(this.config.basepath, hono);
// register flows // register flows

View File

@@ -1,5 +1,6 @@
import { readFile } from "node:fs/promises"; import { readFile } from "node:fs/promises";
import { serveStatic } from "@hono/node-server/serve-static"; import { serveStatic } from "@hono/node-server/serve-static";
import { showRoutes } from "hono/dev";
import { App, registries } from "./src"; import { App, registries } from "./src";
import { StorageLocalAdapter } from "./src/media/storage/adapters/StorageLocalAdapter"; import { StorageLocalAdapter } from "./src/media/storage/adapters/StorageLocalAdapter";
@@ -28,6 +29,7 @@ if (example) {
let app: App; let app: App;
const recreate = import.meta.env.VITE_APP_DISABLE_FRESH !== "1"; const recreate = import.meta.env.VITE_APP_DISABLE_FRESH !== "1";
let routesShown = false;
export default { export default {
async fetch(request: Request) { async fetch(request: Request) {
if (!app || recreate) { if (!app || recreate) {
@@ -44,6 +46,14 @@ export default {
"sync" "sync"
); );
await app.build(); 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); return app.fetch(request);