Skip to content

Commit 8124aec

Browse files
committed
Add build-time config stub for SvelteKit build
During `vite build`, env vars are unavailable so config validation fails. Use SvelteKit's `building` flag to return safe defaults at build time, real config at runtime.
1 parent b5d25cd commit 8124aec

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/lib/config/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { building } from '$app/environment';
12
import { z } from 'zod';
23

34
/**
@@ -181,8 +182,24 @@ function loadConfig(): Config {
181182
}
182183
}
183184

185+
// At build time, env vars are unavailable — use safe defaults
186+
function buildConfig(): Config {
187+
return {
188+
nodeEnv: 'development',
189+
port: 7000,
190+
jwt: { access: { secret: '-' }, refresh: { secret: '-' } },
191+
github: {},
192+
postgate: { url: '-', token: '-', systemTokenSecret: '-' },
193+
sharedStorage: {},
194+
email: {},
195+
mistral: {},
196+
anthropic: {},
197+
appUrl: 'http://localhost:4200'
198+
} as Config;
199+
}
200+
184201
// Export singleton config instance
185-
export const config = loadConfig();
202+
export const config: Config = building ? buildConfig() : loadConfig();
186203

187204
// Export individual sections for convenience
188205
export const { nodeEnv, port, jwt, github, postgate, sharedStorage, mistral, anthropic, email, appUrl } = config;

0 commit comments

Comments
 (0)