You've already forked domainstack.io
mirror of
https://github.com/jakejarvis/domainstack.io.git
synced 2025-12-02 19:33:48 -05:00
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
"use cache";
|
|
|
|
import { get } from "@vercel/edge-config";
|
|
|
|
/**
|
|
* Fetches the default domain suggestions from Vercel Edge Config.
|
|
*
|
|
* Falls back to an empty array if Edge Config is not configured or the key doesn't exist,
|
|
* which shows only user search history without default suggestions.
|
|
*
|
|
* Edge Config key: `domain_suggestions`
|
|
*
|
|
* Expected schema:
|
|
* ```json
|
|
* {
|
|
* "domain_suggestions": [
|
|
* "github.com",
|
|
* "reddit.com",
|
|
* "wikipedia.org",
|
|
* "firefox.com",
|
|
* "jarv.is"
|
|
* ]
|
|
* }
|
|
* ```
|
|
*
|
|
* @returns Array of suggested domain names (empty array if unavailable)
|
|
*/
|
|
export async function getDefaultSuggestions(): Promise<string[]> {
|
|
// If EDGE_CONFIG is not set, return empty array
|
|
if (!process.env.EDGE_CONFIG) {
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
const suggestions = await get<string[]>("domain_suggestions");
|
|
|
|
// Return the suggestions if they exist, otherwise empty array
|
|
return suggestions ?? [];
|
|
} catch (error) {
|
|
// Log the error but fail gracefully
|
|
console.error(
|
|
"[edge-config] failed to fetch domain suggestions",
|
|
error instanceof Error ? error.message : String(error),
|
|
);
|
|
return [];
|
|
}
|
|
}
|