fix: use relative path for PWA push notification URL

This commit is contained in:
weishu
2026-01-03 12:55:09 +08:00
parent 8e03cadcf8
commit 4fe20b74c7
+5 -17
View File
@@ -6,7 +6,7 @@ import type { PushPayload, PushService } from './pushService'
export class PushNotificationChannel implements NotificationChannel {
constructor(
private readonly pushService: PushService,
private readonly appUrl: string
_appUrl: string
) {}
async sendPermissionRequest(session: Session): Promise<void> {
@@ -27,7 +27,7 @@ export class PushNotificationChannel implements NotificationChannel {
data: {
type: 'permission-request',
sessionId: session.id,
url: this.buildSessionUrl(session.id)
url: this.buildSessionPath(session.id)
}
}
@@ -49,26 +49,14 @@ export class PushNotificationChannel implements NotificationChannel {
data: {
type: 'ready',
sessionId: session.id,
url: this.buildSessionUrl(session.id)
url: this.buildSessionPath(session.id)
}
}
await this.pushService.sendToNamespace(session.namespace, payload)
}
private buildSessionUrl(sessionId: string): string {
try {
const baseUrl = new URL(this.appUrl)
const basePath = baseUrl.pathname === '/'
? ''
: baseUrl.pathname.replace(/\/$/, '')
baseUrl.pathname = `${basePath}/sessions/${sessionId}`
baseUrl.search = ''
baseUrl.hash = ''
return baseUrl.toString()
} catch {
const trimmed = this.appUrl.replace(/\/$/, '')
return `${trimmed}/sessions/${sessionId}`
}
private buildSessionPath(sessionId: string): string {
return `/sessions/${sessionId}`
}
}