Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct the path to Strapi's socket when Strapi is served inside a directory #55

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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