refactor: streamline API calls and enhance configuration management

- Refactor multiple API routes to utilize a centralized configuration function for base URL and token management, improving code consistency and maintainability.
- Replace direct environment variable access with a unified config function in the `lib/api.ts` file.
- Remove redundant error handling and streamline response handling in various API endpoints.
- Delete unused job-related API routes and settings, simplifying the overall API structure.
This commit is contained in:
2026-03-09 14:16:01 +01:00
parent 0f5094575a
commit 85cad1a7e7
15 changed files with 71 additions and 272 deletions

View File

@@ -1,20 +1,13 @@
import { NextRequest } from "next/server";
import { config } from "@/lib/api";
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params;
const apiBaseUrl = process.env.API_BASE_URL || "http://api:7080";
const apiToken = process.env.API_BOOTSTRAP_TOKEN;
if (!apiToken) {
return new Response(
`data: ${JSON.stringify({ error: "API token not configured" })}\n\n`,
{ status: 500, headers: { "Content-Type": "text/event-stream" } }
);
}
const { baseUrl, token } = config();
const stream = new ReadableStream({
async start(controller) {
// Send initial headers for SSE
@@ -27,10 +20,8 @@ export async function GET(
if (!isActive) return;
try {
const response = await fetch(`${apiBaseUrl}/index/jobs/${id}`, {
headers: {
Authorization: `Bearer ${apiToken}`,
},
const response = await fetch(`${baseUrl}/index/jobs/${id}`, {
headers: { Authorization: `Bearer ${token}` },
});
if (response.ok && isActive) {