File tree Expand file tree Collapse file tree 6 files changed +57
-13
lines changed Expand file tree Collapse file tree 6 files changed +57
-13
lines changed Original file line number Diff line number Diff line change 1
1
/** @type {import('next').NextConfig } */
2
2
const nextConfig = {
3
3
output : "standalone" ,
4
- basePath : "/ray"
5
4
} ;
6
5
7
6
export default nextConfig ;
Original file line number Diff line number Diff line change
1
+ import { NextResponse } from 'next/server' ;
2
+
3
+ export async function GET ( ) {
4
+ const config = {
5
+ apiUrl : process . env . NEXT_PUBLIC_API_URL || process . env . API_URL || "http://localhost:31888/apis/v1" ,
6
+ } ;
7
+
8
+ return NextResponse . json ( config ) ;
9
+ }
Original file line number Diff line number Diff line change @@ -13,18 +13,24 @@ import {
13
13
import NextLink from "next/link" ;
14
14
import WorkIcon from "@mui/icons-material/Work" ;
15
15
import LanIcon from "@mui/icons-material/Lan" ;
16
- import { useEffect , useState } from "react" ;
16
+ import { useEffect } from "react" ;
17
17
import { useRouter } from "next/navigation" ;
18
18
import { useFirstVisit } from "@/components/FirstVisitContext" ;
19
19
import { roblox } from "@/utils/constants" ;
20
+ import { fetchRuntimeConfig } from "@/utils/constants" ;
21
+
20
22
const HomePage = ( ) => {
21
23
const router = useRouter ( ) ;
22
24
const { firstVisit } = useFirstVisit ( ) ;
25
+
23
26
useEffect ( ( ) => {
27
+ fetchRuntimeConfig ( ) ;
28
+
24
29
if ( firstVisit ) {
25
30
router . push ( "/jobs" ) ;
26
31
}
27
32
} , [ ] )
33
+
28
34
return (
29
35
< >
30
36
< Box
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ import { useSnackBar } from "@/components/SnackBarProvider";
4
4
import { useNamespace } from "@/components/NamespaceProvider" ;
5
5
import { useRouter } from "next/navigation" ;
6
6
import { config } from "@/utils/constants" ;
7
- import { Job } from "@/types/rayjob" ;
8
7
9
8
// TODO: still hard-coded
10
9
async function _createJob (
Original file line number Diff line number Diff line change 1
1
export const ALL_NAMESPACES = "all"
2
- // I'm developing in the stage cluster, so I'm directly using the deployed backend
3
- const development = {
4
- url : "http://localhost:31888/apis/v1" ,
5
- } ;
6
2
7
- const production = {
3
+ interface RuntimeConfig {
4
+ url : string ;
5
+ }
6
+
7
+ const defaultConfig : RuntimeConfig = {
8
8
url : "http://localhost:31888/apis/v1" ,
9
9
} ;
10
10
11
- export const config =
12
- process . env . NODE_ENV === "development" ? development : production ;
11
+ let runtimeConfig : RuntimeConfig | null = null ;
12
+
13
+ export async function fetchRuntimeConfig ( ) : Promise < RuntimeConfig > {
14
+ if ( runtimeConfig ) {
15
+ return runtimeConfig ;
16
+ }
17
+
18
+ try {
19
+ const response = await fetch ( '/api/config' ) ;
20
+ if ( response . ok ) {
21
+ const data = await response . json ( ) ;
22
+ runtimeConfig = {
23
+ url : data . apiUrl || defaultConfig . url ,
24
+ } ;
25
+ return runtimeConfig ;
26
+ }
27
+ } catch ( error ) {
28
+ console . warn ( 'Failed to fetch runtime config, using default:' , error ) ;
29
+ }
30
+
31
+ // Fallback to default config
32
+ runtimeConfig = defaultConfig ;
33
+ return runtimeConfig ;
34
+ }
35
+
36
+ export const config = {
37
+ async getUrl ( ) : Promise < string > {
38
+ const cfg = await fetchRuntimeConfig ( ) ;
39
+ return cfg . url ;
40
+ } ,
41
+
42
+ get url ( ) : string {
43
+ return runtimeConfig ?. url || defaultConfig . url ;
44
+ }
45
+ } ;
13
46
14
47
export const roblox = false ;
Original file line number Diff line number Diff line change @@ -16,9 +16,7 @@ export default async function fetcher(
16
16
endpoint : string ,
17
17
...args : RequestInit [ ]
18
18
) {
19
- const baseUrl = config . url ;
20
- console . log ( `${ baseUrl } ${ endpoint } ` ) ;
21
- // await new Promise((resolve) => setTimeout(resolve, 10000));
19
+ const baseUrl = await config . getUrl ( ) ;
22
20
const res = await fetch ( `${ baseUrl } ${ endpoint } ` , ...args ) ;
23
21
if ( ! res . ok ) {
24
22
const error = new FetchError ( "An error occurred while fetching the data" ) ;
You can’t perform that action at this time.
0 commit comments