|
1
|
import { |
|
2
|
FeatureFlag, |
|
3
|
getConfigFile, |
|
4
|
discoverAndRegisterFeatureFlags, |
|
5
|
} from "@medusajs/framework/utils" |
|
6
|
|
|
7
|
export async function configLoaderOverride( |
|
8
|
entryDirectory: string, |
|
9
|
override: { clientUrl: string; debug?: boolean } |
|
10
|
) { |
|
11
|
const { configManager } = await import("@medusajs/framework/config") |
|
12
|
const { logger } = await import("@medusajs/framework") |
|
13
|
|
|
14
|
await discoverAndRegisterFeatureFlags({ |
|
15
|
flagDir: entryDirectory, |
|
16
|
projectConfigFlags: {}, |
|
17
|
router: FeatureFlag, |
|
18
|
logger, |
|
19
|
}) |
|
20
|
|
|
21
|
const { configModule, error } = await getConfigFile< |
|
22
|
ReturnType<typeof configManager.loadConfig> |
|
23
|
>(entryDirectory, "medusa-config") |
|
24
|
|
|
25
|
if (error) { |
|
26
|
throw new Error(error.message || "Error during config loading") |
|
27
|
} |
|
28
|
|
|
29
|
configModule.projectConfig.databaseDriverOptions |
|
30
|
configModule.projectConfig.databaseUrl = override.clientUrl |
|
31
|
configModule.projectConfig.databaseLogging = !!override.debug |
|
32
|
configModule.projectConfig.databaseDriverOptions = |
|
33
|
override.clientUrl.includes("localhost") |
|
34
|
? {} |
|
35
|
: { |
|
36
|
connection: { |
|
37
|
ssl: { rejectUnauthorized: false }, |
|
38
|
}, |
|
39
|
idle_in_transaction_session_timeout: 20000, |
|
40
|
} |
|
41
|
|
|
42
|
logger.info("Disabling admin as we run integration tests") |
|
43
|
Object.assign(configModule.admin ?? {}, { disable: true }) |
|
44
|
|
|
45
|
configManager.loadConfig({ |
|
46
|
projectConfig: configModule, |
|
47
|
baseDir: entryDirectory, |
|
48
|
}) |
|
49
|
} |