mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 20:06:00 +00:00
electron app - auto find port
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@dbgate/datalib": "^0.1.0",
|
||||
"@dbgate/engines": "^0.1.0",
|
||||
"@dbgate/sqltree": "^0.1.0",
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.3.2",
|
||||
"@testing-library/user-event": "^7.1.2",
|
||||
@@ -21,14 +24,11 @@
|
||||
"resize-observer-polyfill": "^1.5.1",
|
||||
"socket.io-client": "^2.3.0",
|
||||
"styled-components": "^4.4.1",
|
||||
"uuid": "^3.4.0",
|
||||
"@dbgate/sqltree": "^0.1.0",
|
||||
"@dbgate/datalib": "^0.1.0",
|
||||
"@dbgate/engines": "^0.1.0"
|
||||
"uuid": "^3.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "cross-env BROWSER=none PORT=5000 react-scripts start",
|
||||
"build": "cross-env CI=false react-scripts build",
|
||||
"build:docker": "cross-env CI=false REACT_APP_API_URL=ORIGIN react-scripts build",
|
||||
"build:app": "cross-env PUBLIC_URL=. CI=false react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject",
|
||||
@@ -47,8 +47,8 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fortawesome/fontawesome-free": "^5.12.0",
|
||||
"@dbgate/types": "^0.1.0",
|
||||
"@fortawesome/fontawesome-free": "^5.12.0",
|
||||
"@types/react": "^16.9.17",
|
||||
"@types/styled-components": "^4.4.2",
|
||||
"typescript": "^3.7.4"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import io from 'socket.io-client';
|
||||
import React from 'react';
|
||||
import resolveApi from './resolveApi';
|
||||
|
||||
const SocketContext = React.createContext(null);
|
||||
|
||||
@@ -7,7 +8,7 @@ export function SocketProvider({ children }) {
|
||||
const [socket, setSocket] = React.useState();
|
||||
React.useEffect(() => {
|
||||
// const newSocket = io('http://localhost:3000', { transports: ['websocket'] });
|
||||
const newSocket = io('http://localhost:3000');
|
||||
const newSocket = io(resolveApi());
|
||||
setSocket(newSocket);
|
||||
}, []);
|
||||
return <SocketContext.Provider value={socket}>{children}</SocketContext.Provider>;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import resolveApi from './resolveApi';
|
||||
|
||||
export default axios.create({
|
||||
baseURL: 'http://localhost:3000',
|
||||
baseURL: resolveApi(),
|
||||
});
|
||||
|
||||
19
packages/web/src/utility/resolveApi.js
Normal file
19
packages/web/src/utility/resolveApi.js
Normal file
@@ -0,0 +1,19 @@
|
||||
export default function resolveApi() {
|
||||
if (window.require) {
|
||||
const electron = window.require('electron');
|
||||
|
||||
if (electron) {
|
||||
const port = electron.remote.getGlobal('port');
|
||||
return `http://localhost:${port}`;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line
|
||||
const apiUrl = process.env.REACT_APP_API_URL;
|
||||
if (apiUrl) {
|
||||
if (apiUrl == 'ORIGIN') return window.location.origin;
|
||||
return apiUrl;
|
||||
}
|
||||
|
||||
return 'http://localhost:3000';
|
||||
}
|
||||
Reference in New Issue
Block a user