From aa45eb9fa60b254e859750d9cef671daa605b213 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Mon, 26 Feb 2024 08:44:43 -0500 Subject: [PATCH] fix: correct remote url (#10223) * fix: get correct url * chore: changeset * fix: respect runtime env --- .changeset/good-worms-build.md | 5 +++++ packages/db/src/core/integration/vite-plugin-db.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/good-worms-build.md diff --git a/.changeset/good-worms-build.md b/.changeset/good-worms-build.md new file mode 100644 index 000000000000..098237792b7a --- /dev/null +++ b/.changeset/good-worms-build.md @@ -0,0 +1,5 @@ +--- +"@astrojs/db": patch +--- + +Fix: use correct remote database url during production builds diff --git a/packages/db/src/core/integration/vite-plugin-db.ts b/packages/db/src/core/integration/vite-plugin-db.ts index 1aefe84b7b29..bed6cfa8a260 100644 --- a/packages/db/src/core/integration/vite-plugin-db.ts +++ b/packages/db/src/core/integration/vite-plugin-db.ts @@ -1,6 +1,6 @@ import { DB_PATH, RUNTIME_DRIZZLE_IMPORT, RUNTIME_IMPORT, VIRTUAL_MODULE_ID } from '../consts.js'; import type { DBTables } from '../types.js'; -import type { VitePlugin } from '../utils.js'; +import { getRemoteDatabaseUrl, type VitePlugin } from '../utils.js'; const resolvedVirtualModuleId = '\0' + VIRTUAL_MODULE_ID; @@ -79,7 +79,8 @@ import {collectionToTable, createRemoteDatabaseClient} from ${RUNTIME_IMPORT}; export const db = await createRemoteDatabaseClient(${JSON.stringify( appToken - )}, import.meta.env.ASTRO_STUDIO_REMOTE_DB_URL); + // Respect runtime env for user overrides in SSR + )}, import.meta.env.ASTRO_STUDIO_REMOTE_DB_URL ?? ${JSON.stringify(getRemoteDatabaseUrl())}); export * from ${RUNTIME_DRIZZLE_IMPORT}; ${getStringifiedCollectionExports(tables)}