Fix unsubscribe page path, remove pool override, handle Postmark error gracefully

- Fix unsubscribe page path (unsubscribe-success.html → unsubscribe.html)
- Remove netContext.pool.get override that crashed load()
- Handle Postmark registration error gracefully by returning subscription from DB
- Add getSubscriptionByPubkey import to server.ts
This commit is contained in:
Agent 2026-08-18 12:26:07 -04:00
parent 21e7058862
commit 25645e1d0e
2 changed files with 7 additions and 8 deletions

View file

@ -31,10 +31,6 @@ appSigner.getPubkey().then(pubkey => {
console.log(`Running as ${pubkey}`)
})
netContext.pool.get = (url: string) => {
throw new Error('Attempted to use default pool')
}
routerContext.getDefaultRelays = always(DEFAULT_RELAYS)
routerContext.getIndexerRelays = always(INDEXER_RELAYS)
routerContext.getSearchRelays = always(SEARCH_RELAYS)

View file

@ -4,7 +4,7 @@ import rateLimit from 'express-rate-limit'
import { appSigner } from './env.js'
import { render } from './templates.js'
import { confirmSubscriptionAction, unsubscribeAction, registerSubscription, ActionError } from './actions.js'
import { getSubscriptionById, insertEvent, getSubscriptionByKey } from './database.js'
import { getSubscriptionById, insertEvent, getSubscriptionByKey, getSubscriptionByPubkey } from './database.js'
import { load } from '@welshman/net'
import { getIdFilters } from '@welshman/util'
@ -81,8 +81,11 @@ addRoute('post', '/subscription/email', async (req: Request, res: Response) => {
res.json(result)
} catch (error: any) {
// If the error is just Postmark failing, the subscription was still created
if (error.message?.includes('APIKey')) {
res.json({ key: 'fallback', callback: `${process.env.BASE_URL}/notify/fallback` })
// Look up the actual subscription key from the DB
const sub = await getSubscriptionByPubkey(pubkey)
if (sub) {
const callback = `${process.env.BASE_URL}/notify/${sub.id}`
res.json({ key: sub.key, callback })
} else {
console.error('Failed to register subscription:', error)
res.status(500).json({ error: 'Failed to register subscription' })
@ -180,7 +183,7 @@ addRoute('get', '/unsubscribe', async (req: Request, res: Response) => {
// pass
}
res.send(await render('pages/unsubscribe-success.html'))
res.send(await render('pages/unsubscribe.html'))
})
server.use((err: Error, req: Request, res: Response, next: NextFunction) => {