mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-21 00:40:01 +02:00
frontend: getting correct hostname and port
This commit is contained in:
parent
bc0ae0196d
commit
49d7ea30ef
@ -19,7 +19,7 @@
|
|||||||
"web-vitals": "^3.4.0"
|
"web-vitals": "^3.4.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "NODE_ENV=development react-scripts start",
|
||||||
"build": "react-scripts build",
|
"build": "react-scripts build",
|
||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"eject": "react-scripts eject"
|
"eject": "react-scripts eject"
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import { useEffect, useReducer } from 'react';
|
import { useEffect, useReducer } from 'react';
|
||||||
import { socket } from './socket';
|
import { hostname, port, socket } from './socket';
|
||||||
import { DataServiceComponent } from './components/DataServiceComponent';
|
import {
|
||||||
import { DataServiceJSON } from './components/GenericComponent';
|
DataServiceComponent,
|
||||||
|
DataServiceJSON
|
||||||
|
} from './components/DataServiceComponent';
|
||||||
|
|
||||||
type ValueType = boolean | string | number | object;
|
type ValueType = boolean | string | number | object;
|
||||||
|
|
||||||
@ -107,7 +109,7 @@ const App = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Fetch data from the API when the component mounts
|
// Fetch data from the API when the component mounts
|
||||||
fetch('http://localhost:8001/service-properties')
|
fetch(`http://${hostname}:${port}/service-properties`)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data: DataServiceJSON) => dispatch({ type: 'SET_DATA', data }));
|
.then((data: DataServiceJSON) => dispatch({ type: 'SET_DATA', data }));
|
||||||
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import { io } from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
|
|
||||||
const URL = 'ws://localhost:8001/';
|
export const hostname =
|
||||||
// process.env.NODE_ENV === 'production' ? undefined : 'ws://localhost:8001/ws';
|
process.env.NODE_ENV === 'development' ? `localhost` : window.location.hostname;
|
||||||
|
export const port =
|
||||||
|
process.env.NODE_ENV === 'development' ? 8001 : window.location.port;
|
||||||
|
const URL = `ws://${hostname}:${port}/`;
|
||||||
|
console.debug('Websocket: ', URL);
|
||||||
|
|
||||||
export const socket = io(URL, { path: '/ws/socket.io', transports: ['websocket'] });
|
export const socket = io(URL, { path: '/ws/socket.io', transports: ['websocket'] });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user