Browse Source
fix: handle WebSocket URL construction for applications hosted in subfolders or behind proxies
- Updated WebSocket URL logic to dynamically handle subfolder paths.
- Ensured compatibility with applications hosted behind proxies by correctly constructing the WebSocket URL based on the current document location.
- Added support for both `ws://` and `wss://` protocols based on the application's hosting environment.
pull/224/head
Mohamed Ali Elsayed
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
10 additions and
3 deletions
src/views/components/AppLogin.js
src/views/components/AppLogout.js
src/views/index.html
@ -26,7 +26,7 @@ export default {
} ,
} ,
async submitApi ( ) {
async submitApi ( ) {
try {
try {
let response = await window . http . get ( ` /app/login ` )
let response = await window . http . get ( ` . /app/login` )
let results = response . data . results ;
let results = response . data . results ;
this . login_link = results . qr_link ;
this . login_link = results . qr_link ;
this . login_duration_sec = results . qr_duration ;
this . login_duration_sec = results . qr_duration ;
@ -15,7 +15,7 @@ export default {
async submitApi ( ) {
async submitApi ( ) {
try {
try {
await http . get ( ` /app/logout ` )
await http . get ( ` . /app/logout` )
} catch ( error ) {
} catch ( error ) {
if ( error . response ) {
if ( error . response ) {
throw Error ( error . response . data . message )
throw Error ( error . response . data . message )
@ -204,7 +204,14 @@
mounted() {
mounted() {
if (window["WebSocket"]) {
if (window["WebSocket"]) {
let wsType = location.protocol !== 'https:' ? 'ws://' : 'wss://';
let wsType = location.protocol !== 'https:' ? 'ws://' : 'wss://';
this.app_ws = new WebSocket(wsType + document.location.host + "/ws");
let path = document.location.pathname; // Get the full path including the subfolder
// Remove trailing slash if any
if (path.endsWith('/')) {
path = path.slice(0, -1);
}
// Construct the WebSocket URL with the full path
this.app_ws = new WebSocket(wsType + document.location.host + path + "/ws");
this.app_ws.onopen = (evt) => {
this.app_ws.onopen = (evt) => {
this.app_ws.send(JSON.stringify({
this.app_ws.send(JSON.stringify({