From a20b390edd0e182a834fa0facd5f9f76a39ee016 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 9 Jan 2025 00:25:36 +0100 Subject: [PATCH] chore: minor updates --- src/index.ts | 11 ++++++++--- src/types.ts | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index f33a51a..33861aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,19 +25,19 @@ import { deepMerge } from './utils' export async function loadConfig({ name, cwd, - endpoint = '/api/config', + defaultConfig, + endpoint, headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', }, - defaultConfig, }: Config): Promise { // If running in a server (Bun) environment, load the config from the file system if (typeof window === 'undefined') { const configPath = resolve(cwd || process.cwd(), `${name}.config`) try { - const importedConfig = await import(configPath) + const importedConfig = await import(/* @vite-ignore */configPath) const loadedConfig = importedConfig.default || importedConfig return deepMerge(defaultConfig, loadedConfig) as T } @@ -47,6 +47,11 @@ export async function loadConfig({ } } + if (!endpoint) { + console.warn('An endpoint is required to fetch the client config. Using the default config.') + return defaultConfig + } + // If running in a browser environment, load the config from an API endpoint try { const response = await fetch(endpoint, { diff --git a/src/types.ts b/src/types.ts index 7055be8..7e5559b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,10 +7,10 @@ */ export interface Config { name: string + defaultConfig: T cwd?: string endpoint?: string headers?: Record - defaultConfig: T } export type SimplifyDeep = T extends object