mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-05-13 23:16:47 +00:00
38 lines
735 B
TypeScript
38 lines
735 B
TypeScript
import siteConfig from '../site.config'
|
|
|
|
if (!siteConfig) {
|
|
throw new Error(`Config error: invalid site.config.js`)
|
|
}
|
|
|
|
export function getSiteConfig<T>(key: string, defaultValue?: T): T {
|
|
const value = siteConfig[key]
|
|
|
|
if (value !== undefined) {
|
|
return value
|
|
}
|
|
|
|
if (defaultValue !== undefined) {
|
|
return defaultValue
|
|
}
|
|
|
|
throw new Error(`Config error: missing required site config value "${key}"`)
|
|
}
|
|
|
|
export function getEnv(
|
|
key: string,
|
|
defaultValue?: string,
|
|
env = process.env
|
|
): string {
|
|
const value = env[key]
|
|
|
|
if (value !== undefined) {
|
|
return value
|
|
}
|
|
|
|
if (defaultValue !== undefined) {
|
|
return defaultValue
|
|
}
|
|
|
|
throw new Error(`Config error: missing required env variable "${key}"`)
|
|
}
|