Skip to content

Commit 1525dd4

Browse files
authored
Merge pull request #112 from nativeui-org/cursor/investigate-registry-file-not-found-error-be43
2 parents e0468d1 + 96410ad commit 1525dd4

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed
Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { readFileSync } from 'fs';
2-
import { join } from 'path';
31
import { NextResponse } from 'next/server';
42

53
export async function GET(
@@ -10,10 +8,12 @@ export async function GET(
108

119
if (componentName === 'registry' || componentName === 'registry.json') {
1210
try {
13-
const registryFilePath = join(process.cwd(), 'registry.json');
14-
const registryFileContent = readFileSync(registryFilePath, 'utf-8');
15-
const registryData = JSON.parse(registryFileContent);
16-
11+
const url = new URL('/r/registry.json', request.url);
12+
const res = await fetch(url.toString());
13+
if (!res.ok) {
14+
throw new Error(`HTTP ${res.status}`);
15+
}
16+
const registryData = await res.json();
1717
return NextResponse.json(registryData);
1818
} catch (error) {
1919
return new NextResponse(
@@ -28,24 +28,17 @@ export async function GET(
2828
}
2929

3030
try {
31-
const filePath = join(process.cwd(), 'public', 'r', `${componentName}.json`);
32-
const fileContent = readFileSync(filePath, 'utf-8');
33-
const componentData = JSON.parse(fileContent);
34-
31+
const url = new URL(`/r/${componentName}.json`, request.url);
32+
const res = await fetch(url.toString());
33+
if (!res.ok) {
34+
throw new Error(`HTTP ${res.status}`);
35+
}
36+
const componentData = await res.json();
3537
return NextResponse.json(componentData);
3638
} catch (error) {
37-
try {
38-
const legacyFilePath = join(process.cwd(), 'registry', 'ui', `${componentName}.json`);
39-
const legacyFileContent = readFileSync(legacyFilePath, 'utf-8');
40-
const legacyComponentData = JSON.parse(legacyFileContent);
41-
console.error(error);
42-
43-
return NextResponse.json(legacyComponentData);
44-
} catch (legacyError) {
45-
return new NextResponse(
46-
JSON.stringify({ error: `Component ${componentName} not found, ${legacyError}` }),
47-
{ status: 404, headers: { 'content-type': 'application/json' } }
48-
);
49-
}
39+
return new NextResponse(
40+
JSON.stringify({ error: `Component ${componentName} not found, ${error}` }),
41+
{ status: 404, headers: { 'content-type': 'application/json' } }
42+
);
5043
}
5144
}

0 commit comments

Comments
 (0)