dylanebert commited on
Commit
d3a497e
·
1 Parent(s): d366785

dynamic config

Browse files
src/lib/config.ts ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { dev } from '$app/environment';
2
+ import { env } from '$env/dynamic/public';
3
+
4
+ export interface ApiConfig {
5
+ baseUrl: string;
6
+ isLocal: boolean;
7
+ }
8
+
9
+ /**
10
+ * Get API configuration based on environment
11
+ */
12
+ export function getApiConfig(): ApiConfig {
13
+ // Check for explicit environment variable first
14
+ const apiUrl = env.PUBLIC_API_URL;
15
+
16
+ if (apiUrl) {
17
+ return {
18
+ baseUrl: apiUrl,
19
+ isLocal: apiUrl.includes('localhost') || apiUrl.includes('127.0.0.1')
20
+ };
21
+ }
22
+
23
+ // Default behavior: use localhost in dev, production URL in prod
24
+ if (dev) {
25
+ return {
26
+ baseUrl: 'http://localhost:8000',
27
+ isLocal: true
28
+ };
29
+ }
30
+
31
+ return {
32
+ baseUrl: 'https://dylanebert-3d-arena-backend.hf.space',
33
+ isLocal: false
34
+ };
35
+ }
36
+
37
+ /**
38
+ * Get full API endpoint URL
39
+ */
40
+ export function getApiEndpoint(path: string): string {
41
+ const config = getApiConfig();
42
+ return `${config.baseUrl}${path}`;
43
+ }
44
+
45
+ /**
46
+ * Public API endpoints
47
+ */
48
+ export const ApiEndpoints = {
49
+ PAIR: '/pair',
50
+ VOTE: '/vote',
51
+ LEADERBOARD: '/leaderboard',
52
+ } as const;
src/routes/+page.svelte CHANGED
@@ -4,9 +4,11 @@
4
  import Viewer from "./Viewer.svelte";
5
  import Vote from "./Vote.svelte";
6
  import About from "./About.svelte";
7
- import { Filter, CheckmarkOutline } from "carbon-icons-svelte";
8
  import { onMount } from "svelte";
9
- import { CaretDown, Code } from "carbon-icons-svelte";
 
 
10
 
11
  interface Scene {
12
  name: string;
@@ -20,6 +22,9 @@
20
  let showOnlyOpenSource = false;
21
  let showFilter = false;
22
  let filterContainer: HTMLDivElement;
 
 
 
23
 
24
  function handleClickOutside(event: MouseEvent) {
25
  if (filterContainer && !filterContainer.contains(event.target as Node)) {
@@ -50,6 +55,13 @@
50
  </script>
51
 
52
  <div class="container">
 
 
 
 
 
 
 
53
  <div on:pointerdown={goHome} class="banner">
54
  <h1>3D Arena</h1>
55
  <p>Generative 3D Leaderboard</p>
 
4
  import Viewer from "./Viewer.svelte";
5
  import Vote from "./Vote.svelte";
6
  import About from "./About.svelte";
7
+ import { Filter } from "carbon-icons-svelte";
8
  import { onMount } from "svelte";
9
+ import { CaretDown, Code, Development } from "carbon-icons-svelte";
10
+ import { dev } from '$app/environment';
11
+ import { getApiConfig } from '$lib/config';
12
 
13
  interface Scene {
14
  name: string;
 
22
  let showOnlyOpenSource = false;
23
  let showFilter = false;
24
  let filterContainer: HTMLDivElement;
25
+
26
+ $: apiConfig = getApiConfig();
27
+ $: isDevelopment = dev || apiConfig.isLocal;
28
 
29
  function handleClickOutside(event: MouseEvent) {
30
  if (filterContainer && !filterContainer.contains(event.target as Node)) {
 
55
  </script>
56
 
57
  <div class="container">
58
+ {#if isDevelopment}
59
+ <div class="dev-banner">
60
+ <Development size={16} />
61
+ <span>Development Mode - Backend: {apiConfig.baseUrl}</span>
62
+ </div>
63
+ {/if}
64
+
65
  <div on:pointerdown={goHome} class="banner">
66
  <h1>3D Arena</h1>
67
  <p>Generative 3D Leaderboard</p>
src/routes/Vote.svelte CHANGED
@@ -100,7 +100,6 @@
100
  window.addEventListener("resize", handleResize);
101
  handleResize();
102
  } catch (error) {
103
- console.log(error);
104
  errorMessage = "Failed to load scenes.";
105
  }
106
 
@@ -144,7 +143,6 @@
144
 
145
  if (response.ok) {
146
  const result = await response.json();
147
- console.log(result);
148
  setTimeout(() => {
149
  voteOverlayA.classList.remove("show");
150
  voteOverlayB.classList.remove("show");
@@ -197,9 +195,6 @@
197
  }
198
  });
199
 
200
- $: if (data && data.input_path) {
201
- console.log("Input path changed:", data.input_path);
202
- }
203
  </script>
204
 
205
  {#if errorMessage}
 
100
  window.addEventListener("resize", handleResize);
101
  handleResize();
102
  } catch (error) {
 
103
  errorMessage = "Failed to load scenes.";
104
  }
105
 
 
143
 
144
  if (response.ok) {
145
  const result = await response.json();
 
146
  setTimeout(() => {
147
  voteOverlayA.classList.remove("show");
148
  voteOverlayB.classList.remove("show");
 
195
  }
196
  });
197
 
 
 
 
198
  </script>
199
 
200
  {#if errorMessage}
src/routes/api/fetchScenes/+server.ts CHANGED
@@ -1,4 +1,5 @@
1
  import { RequestHandler } from "@sveltejs/kit";
 
2
 
3
  export const GET: RequestHandler = async ({ request }) => {
4
  const authHeader = request.headers.get("authorization");
@@ -7,8 +8,9 @@ export const GET: RequestHandler = async ({ request }) => {
7
  accessToken = authHeader.substring("Bearer ".length);
8
  }
9
 
10
- const url = `https://dylanebert-3d-arena-backend.hf.space/pair?access_token=${accessToken}`;
11
- // const url = `http://localhost:8000/pair?access_token=${access_token}`;
 
12
 
13
  try {
14
  const response = await fetch(url, {
 
1
  import { RequestHandler } from "@sveltejs/kit";
2
+ import { getApiEndpoint, ApiEndpoints } from "$lib/config";
3
 
4
  export const GET: RequestHandler = async ({ request }) => {
5
  const authHeader = request.headers.get("authorization");
 
8
  accessToken = authHeader.substring("Bearer ".length);
9
  }
10
 
11
+ const url = accessToken
12
+ ? `${getApiEndpoint(ApiEndpoints.PAIR)}?access_token=${accessToken}`
13
+ : getApiEndpoint(ApiEndpoints.PAIR);
14
 
15
  try {
16
  const response = await fetch(url, {
src/routes/api/leaderboard/+server.ts CHANGED
@@ -1,5 +1,7 @@
 
 
1
  export const GET = async () => {
2
- const url = `https://dylanebert-3d-arena-backend.hf.space/leaderboard`;
3
 
4
  try {
5
  const response = await fetch(url, {
 
1
+ import { getApiEndpoint, ApiEndpoints } from "$lib/config";
2
+
3
  export const GET = async () => {
4
+ const url = getApiEndpoint(ApiEndpoints.LEADERBOARD);
5
 
6
  try {
7
  const response = await fetch(url, {
src/routes/api/vote/+server.ts CHANGED
@@ -1,4 +1,5 @@
1
  import type { RequestHandler } from "@sveltejs/kit";
 
2
 
3
  export const POST: RequestHandler = async ({ request }) => {
4
  const authHeader = request.headers.get("authorization");
@@ -11,8 +12,7 @@ export const POST: RequestHandler = async ({ request }) => {
11
  const payload = await request.json();
12
  payload.access_token = accessToken;
13
 
14
- const url = `https://dylanebert-3d-arena-backend.hf.space/vote`;
15
- // const url = `http://localhost:8000/vote`;
16
 
17
  try {
18
  const response = await fetch(url, {
 
1
  import type { RequestHandler } from "@sveltejs/kit";
2
+ import { getApiEndpoint, ApiEndpoints } from "$lib/config";
3
 
4
  export const POST: RequestHandler = async ({ request }) => {
5
  const authHeader = request.headers.get("authorization");
 
12
  const payload = await request.json();
13
  payload.access_token = accessToken;
14
 
15
+ const url = getApiEndpoint(ApiEndpoints.VOTE);
 
16
 
17
  try {
18
  const response = await fetch(url, {
static/global.css CHANGED
@@ -614,3 +614,22 @@ body {
614
  letter-spacing: 0.5px;
615
  margin-bottom: 4px;
616
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  letter-spacing: 0.5px;
615
  margin-bottom: 4px;
616
  }
617
+
618
+ .dev-banner {
619
+ background-color: #ff6b35;
620
+ color: #fff;
621
+ padding: 8px 16px;
622
+ display: flex;
623
+ align-items: center;
624
+ gap: 8px;
625
+ font-size: 14px;
626
+ font-weight: 600;
627
+ border-bottom: 1px solid #e55a2b;
628
+ margin: -10px -10px 10px -10px;
629
+ text-align: center;
630
+ justify-content: center;
631
+ }
632
+
633
+ .dev-banner span {
634
+ margin: 0;
635
+ }