-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69fd13f
commit f90a7df
Showing
4 changed files
with
20 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const BASE_URL = | ||
process.env.NODE_ENV === "prod" ? "https://v3.seed-design.io" : "http://localhost:3000"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
import { registryUISchema, type RegistryUIMachineGenerated } from "@/src/schema"; | ||
|
||
const BASE_URL = | ||
process.env.NODE_ENV === "prod" ? "https://v3.seed-design.io" : "http://localhost:3000"; | ||
|
||
export async function fetchRegistryUIItem( | ||
fileNames?: string[], | ||
baseUrl?: string, | ||
): Promise<RegistryUIMachineGenerated> { | ||
try { | ||
const results = await Promise.all( | ||
fileNames.map(async (fileName) => { | ||
const response = await fetch(`${BASE_URL}/__registry__/ui/${fileName}.json`); | ||
const response = await fetch(`${baseUrl}/__registry__/ui/${fileName}.json`); | ||
return await response.json(); | ||
}), | ||
); | ||
|
||
return results; | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error(`Failed to fetch registry from ${BASE_URL}.`); | ||
throw new Error(`Failed to fetch registry from ${baseUrl}.`); | ||
} | ||
} | ||
|
||
export async function getRegistryUIIndex() { | ||
export async function getRegistryUIIndex(baseUrl?: string) { | ||
try { | ||
const [result] = await fetchRegistryUIItem(["index"]); | ||
const [result] = await fetchRegistryUIItem(["index"], baseUrl); | ||
|
||
return registryUISchema.parse(result); | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error(`Failed to fetch components from ${BASE_URL}.`); | ||
throw new Error(`Failed to fetch components from ${baseUrl}.`); | ||
} | ||
} |