Add awaits
This commit is contained in:
parent
f11180db7a
commit
631a5e3e31
8 changed files with 14 additions and 13 deletions
|
@ -1,7 +1,8 @@
|
|||
import { NextResponse } from 'next/server';
|
||||
import process from 'process';
|
||||
|
||||
// In-memory cache for configuration data
|
||||
let cachedConfig: { [key: string]: any } | null = null;
|
||||
let cachedConfig: { [key: string]: string } ;
|
||||
let cacheTimestamp: number | null = null;
|
||||
|
||||
const CACHE_DURATION_MS = 5 * 60 * 1000; // Cache duration: 5 minutes
|
||||
|
@ -22,13 +23,13 @@ async function fetchConfig() {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getServerEnv(envVar: string): Promise<string | null> {
|
||||
export async function await getServerEnv(envVar: string): Promise<string> {
|
||||
// Check if the cache is still valid
|
||||
if (cachedConfig && cacheTimestamp && Date.now() - cacheTimestamp < CACHE_DURATION_MS) {
|
||||
return cachedConfig[envVar] || null;
|
||||
return cachedConfig[envVar] || process.env[envVar];
|
||||
}
|
||||
|
||||
// Fetch and cache the config if not in cache or cache is expired
|
||||
await fetchConfig();
|
||||
return cachedConfig ? cachedConfig[envVar] || null : null;
|
||||
return cachedConfig[envVar];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue