Skip to content

Commit

Permalink
Correct the path to Strapi's socket when Strapi is served inside a di…
Browse files Browse the repository at this point in the history
…rectory (#55)

Correct the path to Strapi's socket
  • Loading branch information
clementprdhomme authored Aug 6, 2024
1 parent 6bbc63a commit f649c12
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion admin/src/modules/alerts/services/alerts-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@ export default class AlertsService {
_streamIdentifier;

constructor() {
this._client = SocketIoClient.connect(process.env.STRAPI_ADMIN_BACKEND_URL);
const uri = process.env.STRAPI_ADMIN_BACKEND_URL;
let path = '/socket.io'; // SocketIoClient defaults to this path too if it is not defined

// If uri is not undefined nor empty, use the correct path to Strapi's socket
if (uri !== undefined && uri.length > 0) {
try {
const { pathname } = new URL(
uri,
window.location.href // Mandatory in case uri is not a complete URL (e.g. /cms)
);
path = `${pathname}${pathname.endsWith('/') ? '' : '/'}socket.io`;
} catch (e) {
console.error(e);
}
}

this._client = SocketIoClient.connect(uri, { path });
}

setStreamIdentifier(streamIdentifier) {
Expand Down

0 comments on commit f649c12

Please sign in to comment.