mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
refactor - backend single bundle
This commit is contained in:
parent
6a13d9fa19
commit
cd58555409
@ -27,7 +27,7 @@ module.exports = {
|
||||
raw: true,
|
||||
},
|
||||
test(req, res) {
|
||||
const subprocess = fork(`${__dirname}/../proc/connectProcess.js`);
|
||||
const subprocess = fork(process.argv[1], ['connectProcess']);
|
||||
subprocess.on('message', resp => res.json(resp));
|
||||
subprocess.send(req.body);
|
||||
},
|
||||
|
@ -31,7 +31,7 @@ module.exports = {
|
||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||
if (existing) return existing;
|
||||
const connection = await connections.get({ conid });
|
||||
const subprocess = fork(`${__dirname}/../proc/databaseConnectionProcess.js`);
|
||||
const subprocess = fork(process.argv[1], ['databaseConnectionProcess']);
|
||||
const newOpened = {
|
||||
conid,
|
||||
database,
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
const connections = require('./connections');
|
||||
const socket = require('../utility/socket');
|
||||
const { fork } = require('child_process');
|
||||
@ -20,7 +19,7 @@ module.exports = {
|
||||
const existing = this.opened.find(x => x.conid == conid);
|
||||
if (existing) return existing;
|
||||
const connection = await connections.get({ conid });
|
||||
const subprocess = fork(`${__dirname}/../proc/serverConnectionProcess.js`);
|
||||
const subprocess = fork(process.argv[1], ['serverConnectionProcess']);
|
||||
const newOpened = {
|
||||
conid,
|
||||
subprocess,
|
||||
|
@ -1,3 +0,0 @@
|
||||
require('./proc');
|
||||
|
||||
module.exports = {};
|
@ -1,9 +1,3 @@
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
const http = require('http');
|
||||
const cors = require('cors');
|
||||
const io = require('socket.io');
|
||||
require('./deps');
|
||||
// require('socket.io-client');
|
||||
|
||||
// "socket.io-client": "^2.3.0",
|
||||
@ -11,29 +5,14 @@ require('./deps');
|
||||
// "uuid": "^3.4.0",
|
||||
// "uws": "10.148.1"
|
||||
|
||||
const processName = process.argv[2];
|
||||
if (processName && processName.endsWith('Process')) {
|
||||
const proc = require('./proc');
|
||||
|
||||
const useController = require('./utility/useController');
|
||||
const connections = require('./controllers/connections');
|
||||
const serverConnections = require('./controllers/serverConnections');
|
||||
const databaseConnections = require('./controllers/databaseConnections');
|
||||
const tables = require('./controllers/tables');
|
||||
const socket = require('./utility/socket');
|
||||
|
||||
const app = express();
|
||||
|
||||
const server = http.createServer(app);
|
||||
socket.set(io(server));
|
||||
|
||||
app.use(cors());
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('DbGate API');
|
||||
});
|
||||
|
||||
useController(app, '/connections', connections);
|
||||
useController(app, '/server-connections', serverConnections);
|
||||
useController(app, '/database-connections', databaseConnections);
|
||||
useController(app, '/tables', tables);
|
||||
|
||||
server.listen(3000);
|
||||
const module = proc[processName];
|
||||
module.start();
|
||||
} else {
|
||||
const main = require('./main');
|
||||
|
||||
main.start();
|
||||
}
|
||||
|
37
packages/api/src/main.js
Normal file
37
packages/api/src/main.js
Normal file
@ -0,0 +1,37 @@
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
const http = require('http');
|
||||
const cors = require('cors');
|
||||
const io = require('socket.io');
|
||||
|
||||
const useController = require('./utility/useController');
|
||||
const connections = require('./controllers/connections');
|
||||
const serverConnections = require('./controllers/serverConnections');
|
||||
const databaseConnections = require('./controllers/databaseConnections');
|
||||
const tables = require('./controllers/tables');
|
||||
const socket = require('./utility/socket');
|
||||
|
||||
function start() {
|
||||
console.log('process.argv', process.argv);
|
||||
|
||||
const app = express();
|
||||
|
||||
const server = http.createServer(app);
|
||||
socket.set(io(server));
|
||||
|
||||
app.use(cors());
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('DbGate API');
|
||||
});
|
||||
|
||||
useController(app, '/connections', connections);
|
||||
useController(app, '/server-connections', serverConnections);
|
||||
useController(app, '/database-connections', databaseConnections);
|
||||
useController(app, '/tables', tables);
|
||||
|
||||
server.listen(3000);
|
||||
}
|
||||
|
||||
module.exports = { start };
|
@ -1,14 +1,18 @@
|
||||
const engines = require('@dbgate/engines');
|
||||
const driverConnect = require('../utility/driverConnect')
|
||||
const driverConnect = require('../utility/driverConnect');
|
||||
|
||||
process.on('message', async connection => {
|
||||
try {
|
||||
const driver = engines(connection);
|
||||
const conn = await driverConnect(driver, connection);
|
||||
const res = await driver.getVersion(conn);
|
||||
process.send(res);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
process.send({ msgtype: 'error', error: e.message });
|
||||
}
|
||||
});
|
||||
function start() {
|
||||
process.on('message', async connection => {
|
||||
try {
|
||||
const driver = engines(connection);
|
||||
const conn = await driverConnect(driver, connection);
|
||||
const res = await driver.getVersion(conn);
|
||||
process.send(res);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
process.send({ msgtype: 'error', error: e.message });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { start };
|
||||
|
@ -56,10 +56,14 @@ async function handleMessage({ msgtype, ...other }) {
|
||||
await handler(other);
|
||||
}
|
||||
|
||||
process.on('message', async message => {
|
||||
try {
|
||||
await handleMessage(message);
|
||||
} catch (e) {
|
||||
process.send({ msgtype: 'error', error: e.message });
|
||||
}
|
||||
});
|
||||
function start() {
|
||||
process.on('message', async message => {
|
||||
try {
|
||||
await handleMessage(message);
|
||||
} catch (e) {
|
||||
process.send({ msgtype: 'error', error: e.message });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { start };
|
||||
|
@ -1,3 +1,9 @@
|
||||
require('./connectProcess');
|
||||
require('./databaseConnectionProcess');
|
||||
require('./serverConnectionProcess');
|
||||
const connectProcess = require('./connectProcess');
|
||||
const databaseConnectionProcess = require('./databaseConnectionProcess');
|
||||
const serverConnectionProcess = require('./serverConnectionProcess');
|
||||
|
||||
module.exports = {
|
||||
connectProcess,
|
||||
databaseConnectionProcess,
|
||||
serverConnectionProcess,
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
const engines = require('@dbgate/engines');
|
||||
const driverConnect = require('../utility/driverConnect')
|
||||
const driverConnect = require('../utility/driverConnect');
|
||||
|
||||
let systemConnection;
|
||||
let storedConnection;
|
||||
@ -28,10 +28,14 @@ async function handleMessage({ msgtype, ...other }) {
|
||||
await handler(other);
|
||||
}
|
||||
|
||||
process.on('message', async message => {
|
||||
try {
|
||||
await handleMessage(message);
|
||||
} catch (e) {
|
||||
process.send({ msgtype: 'error', error: e.message });
|
||||
}
|
||||
});
|
||||
function start() {
|
||||
process.on('message', async message => {
|
||||
try {
|
||||
await handleMessage(message);
|
||||
} catch (e) {
|
||||
process.send({ msgtype: 'error', error: e.message });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { start };
|
||||
|
Loading…
Reference in New Issue
Block a user