@@ -34,16 +34,14 @@ function App({
34
34
pageProps : {
35
35
deploymentUrl,
36
36
adminKey,
37
- listDeploymentsApiUrl,
38
- selectedDeploymentName,
37
+ defaultListDeploymentsApiUrl,
39
38
...pageProps
40
39
} ,
41
40
} : AppProps & {
42
41
pageProps : {
43
42
deploymentUrl : string | null ;
44
43
adminKey : string | null ;
45
- listDeploymentsApiUrl : string | null ;
46
- selectedDeploymentName : string | null ;
44
+ defaultListDeploymentsApiUrl : string | null ;
47
45
} ;
48
46
} ) {
49
47
return (
@@ -60,8 +58,7 @@ function App({
60
58
< DeploymentInfoProvider
61
59
deploymentUrl = { deploymentUrl }
62
60
adminKey = { adminKey }
63
- listDeploymentsApiUrl = { listDeploymentsApiUrl }
64
- selectedDeploymentName = { selectedDeploymentName }
61
+ defaultListDeploymentsApiUrl = { defaultListDeploymentsApiUrl }
65
62
>
66
63
< DeploymentApiProvider deploymentOverride = "local" >
67
64
< WaitForDeploymentApi >
@@ -97,16 +94,15 @@ function normalizeUrl(url: string) {
97
94
App . getInitialProps = async ( { ctx } : { ctx : { req ?: any } } ) => {
98
95
// On server-side, get from process.env
99
96
if ( ctx . req ) {
100
- // This is a relative URL, so add localhost as the origin so it can be parsed
101
- const url = new URL ( ctx . req . url , "http://127.0.0.1" ) ;
97
+ // Note -- we can't use `ctx.req.url` when serving the dashboard statically,
98
+ // so instead we'll read from query params on the client side.
102
99
103
100
let deploymentUrl : string | null = null ;
104
101
if ( process . env . NEXT_PUBLIC_DEPLOYMENT_URL ) {
105
102
deploymentUrl = normalizeUrl ( process . env . NEXT_PUBLIC_DEPLOYMENT_URL ) ;
106
103
}
107
104
108
105
const listDeploymentsApiPort =
109
- url . searchParams . get ( LIST_DEPLOYMENTS_API_PORT_QUERY_PARAM ) ??
110
106
process . env . NEXT_PUBLIC_DEFAULT_LIST_DEPLOYMENTS_API_PORT ;
111
107
let listDeploymentsApiUrl : string | null = null ;
112
108
if ( listDeploymentsApiPort ) {
@@ -116,15 +112,11 @@ App.getInitialProps = async ({ ctx }: { ctx: { req?: any } }) => {
116
112
}
117
113
}
118
114
119
- const selectedDeploymentName =
120
- url . searchParams . get ( SELECTED_DEPLOYMENT_NAME_QUERY_PARAM ) ?? null ;
121
-
122
115
return {
123
116
pageProps : {
124
117
deploymentUrl,
125
118
adminKey : null ,
126
- listDeploymentsApiUrl,
127
- selectedDeploymentName,
119
+ defaultListDeploymentsApiUrl : listDeploymentsApiUrl ,
128
120
} ,
129
121
} ;
130
122
}
@@ -142,7 +134,7 @@ App.getInitialProps = async ({ ctx }: { ctx: { req?: any } }) => {
142
134
pageProps : {
143
135
deploymentUrl : clientSideDeploymentUrl ?? null ,
144
136
adminKey : clientSideAdminKey ?? null ,
145
- listDeploymentsApiUrl : clientSideListDeploymentsApiUrl ?? null ,
137
+ defaultListDeploymentsApiUrl : clientSideListDeploymentsApiUrl ?? null ,
146
138
selectedDeploymentName : clientSideSelectedDeploymentName ?? null ,
147
139
} ,
148
140
} ;
@@ -227,18 +219,19 @@ function DeploymentInfoProvider({
227
219
children,
228
220
deploymentUrl,
229
221
adminKey,
230
- listDeploymentsApiUrl,
231
- selectedDeploymentName,
222
+ defaultListDeploymentsApiUrl,
232
223
} : {
233
224
children : React . ReactNode ;
234
225
deploymentUrl : string | null ;
235
226
adminKey : string | null ;
236
- listDeploymentsApiUrl : string | null ;
237
- selectedDeploymentName : string | null ;
227
+ defaultListDeploymentsApiUrl : string | null ;
238
228
} ) {
239
- const [ shouldListDeployments , setShouldListDeployments ] = useState (
240
- listDeploymentsApiUrl !== null ,
241
- ) ;
229
+ const [ listDeploymentsApiUrl , setListDeploymentsApiUrl ] = useState <
230
+ string | null
231
+ > ( null ) ;
232
+ const [ selectedDeploymentName , setSelectedDeploymentName ] = useState <
233
+ string | null
234
+ > ( null ) ;
242
235
const [ isValidDeploymentInfo , setIsValidDeploymentInfo ] = useState <
243
236
boolean | null
244
237
> ( null ) ;
@@ -297,22 +290,40 @@ function DeploymentInfoProvider({
297
290
useEffect ( ( ) => {
298
291
if ( typeof window !== "undefined" ) {
299
292
const url = new URL ( window . location . href ) ;
293
+ const listDeploymentsApiPort = url . searchParams . get (
294
+ LIST_DEPLOYMENTS_API_PORT_QUERY_PARAM ,
295
+ ) ;
296
+ const selectedDeploymentNameFromUrl = url . searchParams . get (
297
+ SELECTED_DEPLOYMENT_NAME_QUERY_PARAM ,
298
+ ) ;
300
299
url . searchParams . delete ( LIST_DEPLOYMENTS_API_PORT_QUERY_PARAM ) ;
301
300
url . searchParams . delete ( SELECTED_DEPLOYMENT_NAME_QUERY_PARAM ) ;
302
301
window . history . replaceState ( { } , "" , url . toString ( ) ) ;
302
+ if ( listDeploymentsApiPort ) {
303
+ if ( ! Number . isNaN ( parseInt ( listDeploymentsApiPort ) ) ) {
304
+ setListDeploymentsApiUrl (
305
+ normalizeUrl ( `http://127.0.0.1:${ listDeploymentsApiPort } ` ) ,
306
+ ) ;
307
+ }
308
+ } else {
309
+ setListDeploymentsApiUrl ( defaultListDeploymentsApiUrl ) ;
310
+ }
311
+ if ( selectedDeploymentNameFromUrl ) {
312
+ setSelectedDeploymentName ( selectedDeploymentNameFromUrl ) ;
313
+ }
303
314
}
304
- } , [ ] ) ;
315
+ } , [ defaultListDeploymentsApiUrl ] ) ;
305
316
if ( ! mounted ) return null ;
306
317
307
318
if ( ! isValidDeploymentInfo ) {
308
319
return (
309
320
< div className = "flex h-screen w-screen flex-col items-center justify-center gap-8" >
310
321
< ConvexLogo />
311
- { shouldListDeployments && listDeploymentsApiUrl !== null ? (
322
+ { listDeploymentsApiUrl !== null ? (
312
323
< DeploymentList
313
324
listDeploymentsApiUrl = { listDeploymentsApiUrl }
314
325
onError = { ( ) => {
315
- setShouldListDeployments ( false ) ;
326
+ setListDeploymentsApiUrl ( null ) ;
316
327
} }
317
328
onSelect = { onSubmit }
318
329
selectedDeploymentName = { selectedDeploymentName }
0 commit comments