Skip to content

Commit 6fe4504

Browse files
BarneyjmJames Barney
andauthored
fix: Add API routes for auth/validate and auth/status to fix 404 errors (#199)
Co-authored-by: James Barney <[email protected]>
1 parent c6587de commit 6fe4504

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/app/api/auth/status/route.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
3+
const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:8001';
4+
5+
export async function GET(request: NextRequest) {
6+
try {
7+
// Forward the request to the backend API
8+
const response = await fetch(`${TARGET_SERVER_BASE_URL}/auth/status`, {
9+
method: 'GET',
10+
headers: {
11+
'Content-Type': 'application/json',
12+
},
13+
});
14+
15+
if (!response.ok) {
16+
return NextResponse.json(
17+
{ error: `Backend server returned ${response.status}` },
18+
{ status: response.status }
19+
);
20+
}
21+
22+
const data = await response.json();
23+
return NextResponse.json(data);
24+
} catch (error) {
25+
console.error('Error forwarding request to backend:', error);
26+
return NextResponse.json(
27+
{ error: 'Internal Server Error' },
28+
{ status: 500 }
29+
);
30+
}
31+
}

src/app/api/auth/validate/route.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
3+
const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:8001';
4+
5+
export async function POST(request: NextRequest) {
6+
try {
7+
const body = await request.json();
8+
9+
// Forward the request to the backend API
10+
const response = await fetch(`${TARGET_SERVER_BASE_URL}/auth/validate`, {
11+
method: 'POST',
12+
headers: {
13+
'Content-Type': 'application/json',
14+
},
15+
body: JSON.stringify(body),
16+
});
17+
18+
if (!response.ok) {
19+
return NextResponse.json(
20+
{ error: `Backend server returned ${response.status}` },
21+
{ status: response.status }
22+
);
23+
}
24+
25+
const data = await response.json();
26+
return NextResponse.json(data);
27+
} catch (error) {
28+
console.error('Error forwarding request to backend:', error);
29+
return NextResponse.json(
30+
{ error: 'Internal Server Error' },
31+
{ status: 500 }
32+
);
33+
}
34+
}

0 commit comments

Comments
 (0)