Fixed SocketIO calls when pgAdmin 4 server is running from a sub directory. #5521

This commit is contained in:
Aditya Toshniwal 2022-11-15 13:51:12 +05:30 committed by GitHub
parent c5e9aa6357
commit 669a3a7673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 11 deletions

View File

@ -123,7 +123,7 @@ class PgAdmin(Flask):
# like 'localhost/pgadmin4' then we have to append '/pgadmin4'
# into endpoints
#############################################################
wsgi_root_path = None
wsgi_root_path = ''
if url_for('browser.index') != '/browser/':
wsgi_root_path = url_for('browser.index').replace(
'/browser/', ''
@ -133,10 +133,7 @@ class PgAdmin(Flask):
"""
Generate endpoint URL at per WSGI alias
"""
if wsgi_root_path is not None and url:
return wsgi_root_path + url
else:
return url
return wsgi_root_path + url
# Fetch all endpoints and their respective url
for rule in current_app.url_map.iter_rules('static'):
@ -147,6 +144,8 @@ class PgAdmin(Flask):
for rule in current_app.url_map.iter_rules(endpoint):
yield rule.endpoint, get_full_url_path(rule.rule)
yield 'pgadmin.root', wsgi_root_path
@property
def javascripts(self):
scripts = []
@ -928,5 +927,5 @@ def create_app(app_name=None):
##########################################################################
# All done!
##########################################################################
socketio.init_app(app)
socketio.init_app(app, cors_allowed_origins="*")
return app

View File

@ -8,10 +8,12 @@
//////////////////////////////////////////////////////////////
import { io } from 'socketio';
import gettext from 'sources/gettext';
import url_for from 'sources/url_for';
export function openSocket(namespace, options) {
return new Promise((resolve, reject)=>{
const socketObj = io(namespace, {
path: `${url_for('pgadmin.root')}/socket.io`,
pingTimeout: 120000,
pingInterval: 25000,
...options,
@ -24,11 +26,11 @@ export function openSocket(namespace, options) {
socketObj.on('connected', ()=>{
resolve(socketObj);
});
socketObj.on('connect_error', ()=>{
reject();
socketObj.on('connect_error', (err)=>{
reject(err);
});
socketObj.on('disconnect', ()=>{
reject();
socketObj.on('disconnect', (err)=>{
reject(err);
});
});
}

View File

@ -25,6 +25,8 @@ from pgadmin.utils.constants import MIMETYPE_APP_JS
from pgadmin.utils.driver import get_driver
from ... import socketio as sio
from pgadmin.utils import get_complete_file_path
from pgadmin.authenticate import socket_login_required
if _platform == 'win32':
# Check Windows platform support for WinPty api, Disable psql
@ -149,6 +151,7 @@ def set_term_size(fd, row, col, xpix=0, ypix=0):
@sio.on('connect', namespace='/pty')
@socket_login_required
def connect():
"""
Connect to the server through socket.
@ -276,6 +279,7 @@ def pty_handel_io(connection_data, data, sid):
@sio.on('start_process', namespace='/pty')
@socket_login_required
def start_process(data):
"""
Start the pty terminal and execute psql command and emit results to user.

View File

@ -275,7 +275,11 @@ export function initialize(gettext, url_for, $, _, pgAdmin, csrfToken, Browser)
return new SearchAddon();
},
psql_socket: function() {
return io('/pty', {pingTimeout: 120000, pingInterval: 25000});
return io('/pty', {
path: `${url_for('pgadmin.root')}/socket.io`,
pingTimeout: 120000,
pingInterval: 25000
});
},
set_theme: function(term) {
let theme = {