Remove diagnostic debug code and backend endpoint
This commit is contained in:
@@ -14,7 +14,6 @@ import {
|
|||||||
reconcileVersionOnStartup
|
reconcileVersionOnStartup
|
||||||
} from './services/pwaStartup.ts'
|
} from './services/pwaStartup.ts'
|
||||||
import { redirectToPasskeyCompatibleHostIfNeeded } from './utils/passkeyHost.ts'
|
import { redirectToPasskeyCompatibleHostIfNeeded } from './utils/passkeyHost.ts'
|
||||||
import { logToBackend } from './services/pushNotifications.ts'
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -75,16 +74,13 @@ async function bootstrap(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('serviceWorker' in navigator && !import.meta.env.DEV) {
|
if ('serviceWorker' in navigator && !import.meta.env.DEV) {
|
||||||
logToBackend('Attempting manual Service Worker registration...')
|
|
||||||
navigator.serviceWorker
|
navigator.serviceWorker
|
||||||
.register('/sw.js', { scope: '/' })
|
.register('/sw.js', { scope: '/' })
|
||||||
.then((reg) => {
|
.then((reg) => {
|
||||||
console.log('Service Worker registered successfully with scope:', reg.scope)
|
console.log('Service Worker registered successfully with scope:', reg.scope)
|
||||||
logToBackend('Service Worker registered successfully with scope: ' + reg.scope)
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('Service Worker registration failed:', err)
|
console.error('Service Worker registration failed:', err)
|
||||||
logToBackend('Service Worker registration failed', err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,29 +2,6 @@ import { apiFetch, apiJson } from './api.js'
|
|||||||
|
|
||||||
const API_BASE = '/api/push'
|
const API_BASE = '/api/push'
|
||||||
|
|
||||||
export async function logToBackend(message: string, error?: any): Promise<void> {
|
|
||||||
try {
|
|
||||||
await fetch(`${API_BASE}/debug-log`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({
|
|
||||||
message,
|
|
||||||
error: error ? {
|
|
||||||
name: error.name,
|
|
||||||
message: error.message,
|
|
||||||
stack: error.stack,
|
|
||||||
...error
|
|
||||||
} : undefined,
|
|
||||||
userAgent: navigator.userAgent,
|
|
||||||
href: window.location.href,
|
|
||||||
timestamp: new Date().toISOString()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Failed to send debug log:', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function urlBase64ToUint8Array(base64String: string): Uint8Array {
|
function urlBase64ToUint8Array(base64String: string): Uint8Array {
|
||||||
const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
|
const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
|
||||||
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/')
|
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/')
|
||||||
@@ -212,35 +189,23 @@ async function saveSubscriptionToServer(subscription: PushSubscription): Promise
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function subscribeToPush(): Promise<void> {
|
export async function subscribeToPush(): Promise<void> {
|
||||||
logToBackend('subscribeToPush called')
|
|
||||||
if (!isPushSupported()) {
|
if (!isPushSupported()) {
|
||||||
logToBackend('subscribeToPush: push not supported')
|
|
||||||
throw new Error('Push notifications are not supported on this device')
|
throw new Error('Push notifications are not supported on this device')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pre-resolve registration using getRegistrationCompat to prevent ready state hangs
|
// Pre-resolve registration using getRegistrationCompat to prevent ready state hangs
|
||||||
let registration = cachedRegistration
|
let registration = cachedRegistration
|
||||||
if (!registration) {
|
if (!registration) {
|
||||||
try {
|
registration = await getRegistrationCompat()
|
||||||
logToBackend('subscribeToPush: getting registration...')
|
cachedRegistration = registration
|
||||||
registration = await getRegistrationCompat()
|
|
||||||
cachedRegistration = registration
|
|
||||||
logToBackend('subscribeToPush: got registration successfully')
|
|
||||||
} catch (err) {
|
|
||||||
logToBackend('subscribeToPush: failed to get registration', err)
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const publicKey = cachedVapidKey || await fetchVapidPublicKey()
|
const publicKey = cachedVapidKey || await fetchVapidPublicKey()
|
||||||
if (!publicKey) {
|
if (!publicKey) {
|
||||||
logToBackend('subscribeToPush: no public key available')
|
|
||||||
throw new Error('Push notifications are not configured on this server')
|
throw new Error('Push notifications are not configured on this server')
|
||||||
}
|
}
|
||||||
|
|
||||||
logToBackend('subscribeToPush: requesting permission...')
|
|
||||||
const permission = await requestNotificationPermission()
|
const permission = await requestNotificationPermission()
|
||||||
logToBackend(`subscribeToPush: permission result: ${permission}`)
|
|
||||||
if (permission !== 'granted') {
|
if (permission !== 'granted') {
|
||||||
throw new Error('Notification permission denied')
|
throw new Error('Notification permission denied')
|
||||||
}
|
}
|
||||||
@@ -249,7 +214,6 @@ export async function subscribeToPush(): Promise<void> {
|
|||||||
const applicationServerKey = new Uint8Array(keyBytes)
|
const applicationServerKey = new Uint8Array(keyBytes)
|
||||||
|
|
||||||
// Always call subscribe with timeout to prevent silent hangs on push network errors
|
// Always call subscribe with timeout to prevent silent hangs on push network errors
|
||||||
logToBackend('subscribeToPush: subscribing via pushManager...')
|
|
||||||
const subscribePromise = registration.pushManager.subscribe({
|
const subscribePromise = registration.pushManager.subscribe({
|
||||||
userVisibleOnly: true,
|
userVisibleOnly: true,
|
||||||
applicationServerKey
|
applicationServerKey
|
||||||
@@ -257,15 +221,9 @@ export async function subscribeToPush(): Promise<void> {
|
|||||||
const subscribeTimeout = new Promise<never>((_, reject) =>
|
const subscribeTimeout = new Promise<never>((_, reject) =>
|
||||||
setTimeout(() => reject(new Error('Timeout establishing subscription with push service (FCM/APNs)')), 12000)
|
setTimeout(() => reject(new Error('Timeout establishing subscription with push service (FCM/APNs)')), 12000)
|
||||||
)
|
)
|
||||||
try {
|
const subscription = await Promise.race([subscribePromise, subscribeTimeout])
|
||||||
const subscription = await Promise.race([subscribePromise, subscribeTimeout])
|
|
||||||
logToBackend('subscribeToPush: subscribed successfully, saving to server...')
|
await saveSubscriptionToServer(subscription)
|
||||||
await saveSubscriptionToServer(subscription)
|
|
||||||
logToBackend('subscribeToPush: saved to server successfully')
|
|
||||||
} catch (err) {
|
|
||||||
logToBackend('subscribeToPush: subscription or save failed', err)
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unsubscribeFromPush(): Promise<void> {
|
export async function unsubscribeFromPush(): Promise<void> {
|
||||||
|
|||||||
@@ -22,11 +22,6 @@ router.get('/vapid-public-key', (_req, res) => {
|
|||||||
return res.json({ publicKey })
|
return res.json({ publicKey })
|
||||||
})
|
})
|
||||||
|
|
||||||
router.post('/debug-log', (req, res) => {
|
|
||||||
console.log('[CLIENT_DEBUG]', req.body)
|
|
||||||
return res.json({ success: true })
|
|
||||||
})
|
|
||||||
|
|
||||||
router.use(requireUser)
|
router.use(requireUser)
|
||||||
|
|
||||||
router.get('/prefs', async (req: any, res) => {
|
router.get('/prefs', async (req: any, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user