diff --git a/app/package.json b/app/package.json index c4f4f56..87be1c9 100644 --- a/app/package.json +++ b/app/package.json @@ -74,6 +74,7 @@ "@vitejs/plugin-react": "^4.3.3", "autoprefixer": "^10.4.20", "clsx": "^2.1.1", + "dotenv": "^16.4.7", "esbuild-postcss": "^0.0.4", "jotai": "^2.10.1", "kysely-d1": "^0.3.0", diff --git a/app/src/cli/commands/run/platform.ts b/app/src/cli/commands/run/platform.ts index 3038181..86758dc 100644 --- a/app/src/cli/commands/run/platform.ts +++ b/app/src/cli/commands/run/platform.ts @@ -76,3 +76,9 @@ export async function getConfigPath(filePath?: string) { return; } + +export function getConnectionCredentialsFromEnv() { + const dbUrl = process.env.DB_URL; + const dbToken = process.env.DB_TOKEN; + return dbUrl ? { url: dbUrl, authToken: dbToken } : undefined; +} diff --git a/app/src/cli/commands/run/run.ts b/app/src/cli/commands/run/run.ts index 7911053..a34a65c 100644 --- a/app/src/cli/commands/run/run.ts +++ b/app/src/cli/commands/run/run.ts @@ -4,15 +4,18 @@ import { StorageLocalAdapter } from "adapter/node"; import type { CliBkndConfig, CliCommand } from "cli/types"; import { Option } from "commander"; import { config } from "core"; +import dotenv from "dotenv"; import { registries } from "modules/registries"; import { PLATFORMS, type Platform, attachServeStatic, getConfigPath, + getConnectionCredentialsFromEnv, startServer } from "./platform"; +dotenv.config(); const isBun = typeof Bun !== "undefined"; export const run: CliCommand = (program) => { @@ -101,16 +104,26 @@ async function action(options: { }) { const configFilePath = await getConfigPath(options.config); - let app: App; - if (options.dbUrl || !configFilePath) { + let app: App | undefined = undefined; + if (options.dbUrl) { const connection = options.dbUrl ? { url: options.dbUrl, authToken: options.dbToken } : undefined; app = await makeApp({ connection, server: { platform: options.server } }); - } else { - console.log("Using config from:", configFilePath); + } else if (configFilePath) { + console.log("[INFO] Using config from:", configFilePath); const config = (await import(configFilePath).then((m) => m.default)) as CliBkndConfig; app = await makeConfigApp(config, options.server); + } else { + const credentials = getConnectionCredentialsFromEnv(); + if (credentials) { + console.log("[INFO] Using connection from environment"); + app = await makeConfigApp({ app: { connection: credentials } }, options.server); + } + } + + if (!app) { + app = await makeApp({ server: { platform: options.server } }); } await startServer(options.server, app, { port: options.port }); diff --git a/app/src/data/connection/SqliteIntrospector.ts b/app/src/data/connection/SqliteIntrospector.ts index f86887e..516e8cf 100644 --- a/app/src/data/connection/SqliteIntrospector.ts +++ b/app/src/data/connection/SqliteIntrospector.ts @@ -107,7 +107,6 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro } const tables = await query.execute(); - console.log("tables", tables); return Promise.all(tables.map(({ name }) => this.#getTableMetadata(name))); } @@ -119,7 +118,6 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro async #getTableMetadata(table: string): Promise { const db = this.#db; - console.log("get table metadata", table); // Get the SQL that was used to create the table. const tableDefinition = await db diff --git a/bun.lockb b/bun.lockb index ff10b8a..80a2b5b 100755 Binary files a/bun.lockb and b/bun.lockb differ