mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 23:06:00 +00:00
runAsPortal - connections from env variables, cannot be changed
This commit is contained in:
8
packages/api/src/controllers/config.js
Normal file
8
packages/api/src/controllers/config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
get_meta: 'get',
|
||||
async get() {
|
||||
return {
|
||||
runAsPortal: !!process.env.CONNECTIONS,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -6,19 +6,37 @@ const nedb = require('nedb-promises');
|
||||
const { datadir } = require('../utility/directories');
|
||||
const socket = require('../utility/socket');
|
||||
|
||||
function getPortalCollections() {
|
||||
if (process.env.CONNECTIONS) {
|
||||
return _.compact(process.env.CONNECTIONS.split(',')).map((id) => ({
|
||||
_id: id,
|
||||
engine: process.env[`ENGINE_${id}`],
|
||||
server: process.env[`SERVER_${id}`],
|
||||
user: process.env[`USER_${id}`],
|
||||
password: process.env[`PASSWORD_${id}`],
|
||||
port: process.env[`PORT_${id}`],
|
||||
displayName: process.env[`LABEL_${id}`],
|
||||
}));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const portalConnections = getPortalCollections();
|
||||
|
||||
module.exports = {
|
||||
datastore: null,
|
||||
opened: [],
|
||||
|
||||
async _init() {
|
||||
const dir = datadir();
|
||||
// @ts-ignore
|
||||
this.datastore = nedb.create(path.join(dir, 'connections.jsonl'));
|
||||
if (!portalConnections) {
|
||||
// @ts-ignore
|
||||
this.datastore = nedb.create(path.join(dir, 'connections.jsonl'));
|
||||
}
|
||||
},
|
||||
|
||||
list_meta: 'get',
|
||||
async list() {
|
||||
return this.datastore.find();
|
||||
return portalConnections || this.datastore.find();
|
||||
},
|
||||
|
||||
test_meta: {
|
||||
@@ -39,6 +57,7 @@ module.exports = {
|
||||
|
||||
save_meta: 'post',
|
||||
async save(connection) {
|
||||
if (portalConnections) return;
|
||||
let res;
|
||||
if (connection._id) {
|
||||
res = await this.datastore.update(_.pick(connection, '_id'), connection);
|
||||
@@ -51,6 +70,7 @@ module.exports = {
|
||||
|
||||
delete_meta: 'post',
|
||||
async delete(connection) {
|
||||
if (portalConnections) return;
|
||||
const res = await this.datastore.remove(_.pick(connection, '_id'));
|
||||
socket.emitChanged('connection-list-changed');
|
||||
return res;
|
||||
@@ -58,6 +78,7 @@ module.exports = {
|
||||
|
||||
get_meta: 'get',
|
||||
async get({ conid }) {
|
||||
if (portalConnections) return portalConnections.find((x) => x._id == conid);
|
||||
const res = await this.datastore.find({ _id: conid });
|
||||
return res[0];
|
||||
},
|
||||
|
||||
@@ -16,6 +16,7 @@ const databaseConnections = require('./controllers/databaseConnections');
|
||||
const metadata = require('./controllers/metadata');
|
||||
const sessions = require('./controllers/sessions');
|
||||
const jsldata = require('./controllers/jsldata');
|
||||
const config = require('./controllers/config');
|
||||
|
||||
function start(argument = null) {
|
||||
console.log('process.argv', process.argv);
|
||||
@@ -34,6 +35,7 @@ function start(argument = null) {
|
||||
useController(app, '/metadata', metadata);
|
||||
useController(app, '/sessions', sessions);
|
||||
useController(app, '/jsldata', jsldata);
|
||||
useController(app, '/config', config);
|
||||
|
||||
if (fs.existsSync('/home/dbgate-docker/build')) {
|
||||
// server static files inside docker container
|
||||
|
||||
Reference in New Issue
Block a user