mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 09:03:58 +00:00
#228 running dbgate on subpath
This commit is contained in:
@@ -4,7 +4,7 @@ version: "3"
|
|||||||
services:
|
services:
|
||||||
dbgate:
|
dbgate:
|
||||||
build: docker
|
build: docker
|
||||||
# image: dbgate/dbgate:beta
|
# image: dbgate/dbgate:beta-alpine
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 3100:3000
|
- 3100:3000
|
||||||
@@ -14,6 +14,9 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- dbgate-data:/root/dbgate-data
|
- dbgate-data:/root/dbgate-data
|
||||||
|
|
||||||
|
# environment:
|
||||||
|
# WEB_ROOT: /dbgate
|
||||||
|
|
||||||
# volumes:
|
# volumes:
|
||||||
# - /home/jena/test/chinook:/mnt/sqt
|
# - /home/jena/test/chinook:/mnt/sqt
|
||||||
# environment:
|
# environment:
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ const queryHistory = require('./controllers/queryHistory');
|
|||||||
|
|
||||||
const { rundir } = require('./utility/directories');
|
const { rundir } = require('./utility/directories');
|
||||||
const platformInfo = require('./utility/platformInfo');
|
const platformInfo = require('./utility/platformInfo');
|
||||||
|
const getExpressPath = require('./utility/getExpressPath');
|
||||||
let checkLocalhostOrigin = null;
|
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
// console.log('process.argv', process.argv);
|
// console.log('process.argv', process.argv);
|
||||||
@@ -50,29 +49,9 @@ function start() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
|
||||||
if (checkLocalhostOrigin) {
|
|
||||||
if (
|
|
||||||
req.headers.origin &&
|
|
||||||
req.headers.origin != checkLocalhostOrigin &&
|
|
||||||
req.headers.origin != `http://${checkLocalhostOrigin}`
|
|
||||||
) {
|
|
||||||
console.log('API origin check FAILED');
|
|
||||||
console.log('HEADERS', { ...req.headers, authorization: '***' });
|
|
||||||
return res.status(403).json({ error: 'Not authorized!' });
|
|
||||||
}
|
|
||||||
if (!req.headers.origin && req.headers.host != checkLocalhostOrigin) {
|
|
||||||
console.log('API host check FAILED');
|
|
||||||
console.log('HEADERS', { ...req.headers, authorization: '***' });
|
|
||||||
return res.status(403).json({ error: 'Not authorized!' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
app.get('/stream', async function (req, res) {
|
app.get(getExpressPath('/stream'), async function (req, res) {
|
||||||
res.set({
|
res.set({
|
||||||
'Cache-Control': 'no-cache',
|
'Cache-Control': 'no-cache',
|
||||||
'Content-Type': 'text/event-stream',
|
'Content-Type': 'text/event-stream',
|
||||||
@@ -88,7 +67,7 @@ function start() {
|
|||||||
app.use(bodyParser.json({ limit: '50mb' }));
|
app.use(bodyParser.json({ limit: '50mb' }));
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
'/uploads',
|
getExpressPath('/uploads'),
|
||||||
fileUpload({
|
fileUpload({
|
||||||
limits: { fileSize: 4 * 1024 * 1024 },
|
limits: { fileSize: 4 * 1024 * 1024 },
|
||||||
})
|
})
|
||||||
@@ -100,21 +79,21 @@ function start() {
|
|||||||
// app.use('/pages', express.static(process.env.PAGES_DIRECTORY));
|
// app.use('/pages', express.static(process.env.PAGES_DIRECTORY));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
app.use('/runners/data', express.static(rundir()));
|
app.use(getExpressPath('/runners/data'), express.static(rundir()));
|
||||||
|
|
||||||
if (platformInfo.isDocker) {
|
if (platformInfo.isDocker) {
|
||||||
// server static files inside docker container
|
// server static files inside docker container
|
||||||
app.use(express.static('/home/dbgate-docker/public'));
|
app.use(getExpressPath('/'), express.static('/home/dbgate-docker/public'));
|
||||||
} else {
|
} else {
|
||||||
if (!platformInfo.isNpmDist) {
|
if (!platformInfo.isNpmDist) {
|
||||||
app.get('/', (req, res) => {
|
app.get(getExpressPath('/'), (req, res) => {
|
||||||
res.send('DbGate API');
|
res.send('DbGate API');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (platformInfo.isNpmDist) {
|
if (platformInfo.isNpmDist) {
|
||||||
app.use(express.static(path.join(__dirname, '../../dbgate-web/public')));
|
app.use(getExpressPath('/'), express.static(path.join(__dirname, '../../dbgate-web/public')));
|
||||||
getPort({ port: 5000 }).then(port => {
|
getPort({ port: 5000 }).then(port => {
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
console.log(`DbGate API listening on port ${port}`);
|
console.log(`DbGate API listening on port ${port}`);
|
||||||
|
|||||||
10
packages/api/src/utility/getExpressPath.js
Normal file
10
packages/api/src/utility/getExpressPath.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
function getExpressPath(path) {
|
||||||
|
path = path.replace(/\/*$/, '').replace(/^\/*/, '');
|
||||||
|
const root = (process.env.WEB_ROOT || '').replace(/^\/*/, '').replace(/\/*$/, '');
|
||||||
|
if (root) {
|
||||||
|
return `/${root}/${path}`;
|
||||||
|
}
|
||||||
|
return `/${path}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getExpressPath;
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
const getExpressPath = require('./getExpressPath');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} route
|
* @param {string} route
|
||||||
@@ -74,6 +75,6 @@ module.exports = function useController(app, electron, route, controller) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (app) {
|
if (app) {
|
||||||
app.use(route, router);
|
app.use(getExpressPath(route), router);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default function resolveApi() {
|
|||||||
if (apiUrl) {
|
if (apiUrl) {
|
||||||
return apiUrl;
|
return apiUrl;
|
||||||
}
|
}
|
||||||
return window.location.origin;
|
return window.location.href.replace(/\/*$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveApiHeaders() {
|
export function resolveApiHeaders() {
|
||||||
|
|||||||
Reference in New Issue
Block a user