This repository was archived by the owner on Apr 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change
1
+ 8080
Original file line number Diff line number Diff line change 1
- import Axios from "axios" ;
1
+ import Axios , { AxiosResponse } from "axios" ;
2
2
3
- const uri = "http://localhost:8080" ;
3
+ let uri :string ;
4
+ const localhost :string = "http://localhost:" ;
5
+ const backendPortFilePath :string = "./backend.cfg" ;
6
+
7
+ function setBackendPort ( ) :Promise < string > {
8
+ return new Promise ( ( resolve , reject ) => {
9
+ Axios . get ( backendPortFilePath )
10
+ . then ( ( data :AxiosResponse < string > ) => {
11
+ uri = localhost + data . data ;
12
+ console . log ( `[API] ${ uri } ` )
13
+ resolve ( data . data ) ;
14
+ } )
15
+ . catch ( ( ( error :any ) => {
16
+ reject ( error ) ;
17
+ } ) ) ;
18
+ } ) ;
19
+ }
4
20
5
21
interface BackendHealthData {
6
22
uptimeInSeconds : number
@@ -18,4 +34,4 @@ function callBackendHealth():Promise<BackendHealthData>{
18
34
} ) ;
19
35
}
20
36
21
- export { callBackendHealth }
37
+ export { setBackendPort , callBackendHealth }
Original file line number Diff line number Diff line change 1
1
import React , { ReactElement , useEffect , useState } from 'react' ;
2
2
import logo from '../logo.svg' ;
3
3
import './App.css' ;
4
- import { callBackendHealth } from "../api" ;
4
+ import { setBackendPort , callBackendHealth } from "../api" ;
5
5
6
- function App ( ) :ReactElement {
6
+ function App ( ) : ReactElement {
7
7
const [ backendLiveTime , setBackendLiveTime ] = useState < number | string > ( "Init" ) ;
8
8
9
9
useEffect ( ( ) => {
10
- updateVariables ( )
10
+ Promise . resolve ( setBackendPort ( ) )
11
+ . then ( ( backendPort :string ) => {
12
+ console . log ( "[APP] Backend-Port = " + backendPort )
13
+ callInitialBackendRequests ( )
14
+ } )
15
+ . catch ( ( error :any ) => {
16
+ alert ( "Error: Problems with backend.cfg - " + error )
17
+ } )
11
18
} ) ;
12
19
20
+ function callInitialBackendRequests ( ) :void {
21
+ updateVariables ( )
22
+ }
23
+
13
24
function updateVariables ( ) : void {
14
25
Promise . all ( [ callBackendHealth ( ) ] )
15
26
. then ( ( [ backendHealthData ] ) => {
You can’t perform that action at this time.
0 commit comments