Browse Source

endpoint error fix

Timothy J. Baek 1 year ago
parent
commit
ecb4d1b8d9
2 changed files with 16 additions and 14 deletions
  1. 5 8
      src/lib/contants.ts
  2. 11 6
      src/routes/+page.server.ts

+ 5 - 8
src/lib/contants.ts

@@ -1,10 +1,7 @@
 import { browser, dev } from '$app/environment';
 import { browser, dev } from '$app/environment';
 
 
-export const ENDPOINT =
-	process.env.OLLAMA_ENDPOINT != undefined
-		? process.env.OLLAMA_ENDPOINT
-		: browser
-		? `http://${location.hostname}:11434`
-		: dev
-		? 'http://127.0.0.1:11434'
-		: 'http://host.docker.internal:11434';
+export const ENDPOINT = browser
+	? `http://${location.hostname}:11434`
+	: dev
+	? 'http://127.0.0.1:11434'
+	: 'http://host.docker.internal:11434';

+ 11 - 6
src/routes/+page.server.ts

@@ -2,13 +2,18 @@ import { ENDPOINT } from '$lib/contants';
 import type { PageServerLoad } from './$types';
 import type { PageServerLoad } from './$types';
 
 
 export const load: PageServerLoad = async ({ url }) => {
 export const load: PageServerLoad = async ({ url }) => {
-	const models = await fetch(`${ENDPOINT}/api/tags`, {
-		method: 'GET',
-		headers: {
-			Accept: 'application/json',
-			'Content-Type': 'application/json'
+	const OLLAMA_ENDPOINT = process.env.OLLAMA_ENDPOINT;
+	console.log(OLLAMA_ENDPOINT);
+	const models = await fetch(
+		`${OLLAMA_ENDPOINT != undefined ? OLLAMA_ENDPOINT : ENDPOINT}/api/tags`,
+		{
+			method: 'GET',
+			headers: {
+				Accept: 'application/json',
+				'Content-Type': 'application/json'
+			}
 		}
 		}
-	})
+	)
 		.then(async (res) => {
 		.then(async (res) => {
 			if (!res.ok) throw await res.json();
 			if (!res.ok) throw await res.json();
 			return res.json();
 			return res.json();