fix(meilisearch): load .env in config for worker context; ensures correct master key

This commit is contained in:
ggq-admin 2025-10-19 17:09:32 +02:00
parent 2b9ea81e60
commit 688dc3d231

View file

@ -3,11 +3,14 @@
*/ */
import { MeiliSearch } from 'meilisearch'; import { MeiliSearch } from 'meilisearch';
import dotenv from 'dotenv';
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import { dirname, join } from 'path'; import { dirname, join } from 'path';
const __dirname = dirname(fileURLToPath(import.meta.url)); const __dirname = dirname(fileURLToPath(import.meta.url));
// Ensure environment is loaded for both API and worker contexts
dotenv.config({ path: join(__dirname, '../.env') });
const MEILISEARCH_HOST = process.env.MEILISEARCH_HOST || 'http://127.0.0.1:7700'; const MEILISEARCH_HOST = process.env.MEILISEARCH_HOST || 'http://127.0.0.1:7700';
const MEILISEARCH_MASTER_KEY = process.env.MEILISEARCH_MASTER_KEY || 'changeme123'; const MEILISEARCH_MASTER_KEY = process.env.MEILISEARCH_MASTER_KEY || 'changeme123';