50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import { getConfig } from "@/lib/config";
|
|
|
|
export async function GET() {
|
|
try {
|
|
const result = getConfig();
|
|
|
|
if (!result.ok) {
|
|
return Response.json({
|
|
configPresent: false,
|
|
baseUrl: null,
|
|
model: null,
|
|
reachable: false,
|
|
error: "Missing or invalid environment configuration",
|
|
}, { status: 500 });
|
|
}
|
|
|
|
const { OLLAMA_BASE_URL, OLLAMA_MODEL } = result.config;
|
|
|
|
// Test reachability with a short timeout
|
|
let reachable = false;
|
|
let reachError = null;
|
|
|
|
try {
|
|
const controller = new AbortController();
|
|
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
|
|
const res = await fetch(`${OLLAMA_BASE_URL}/api/tags`, {
|
|
signal: controller.signal
|
|
});
|
|
clearTimeout(timeout);
|
|
reachable = res.ok;
|
|
} catch (e) {
|
|
reachError = e.message || "Connection failed";
|
|
}
|
|
|
|
return Response.json({
|
|
configPresent: true,
|
|
baseUrl: OLLAMA_BASE_URL,
|
|
model: OLLAMA_MODEL,
|
|
reachable,
|
|
error: reachable ? null : (`Could not reach Ollama at ${OLLAMA_BASE_URL}: ${reachError || "timeout"}`),
|
|
});
|
|
} catch (e) {
|
|
return Response.json(
|
|
{ configPresent: false, error: e.message },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|