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:
parent
21e7058862
commit
25645e1d0e
2 changed files with 7 additions and 8 deletions
|
|
@ -31,10 +31,6 @@ appSigner.getPubkey().then(pubkey => {
|
||||||
console.log(`Running as ${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.getDefaultRelays = always(DEFAULT_RELAYS)
|
||||||
routerContext.getIndexerRelays = always(INDEXER_RELAYS)
|
routerContext.getIndexerRelays = always(INDEXER_RELAYS)
|
||||||
routerContext.getSearchRelays = always(SEARCH_RELAYS)
|
routerContext.getSearchRelays = always(SEARCH_RELAYS)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import rateLimit from 'express-rate-limit'
|
||||||
import { appSigner } from './env.js'
|
import { appSigner } from './env.js'
|
||||||
import { render } from './templates.js'
|
import { render } from './templates.js'
|
||||||
import { confirmSubscriptionAction, unsubscribeAction, registerSubscription, ActionError } from './actions.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 { load } from '@welshman/net'
|
||||||
import { getIdFilters } from '@welshman/util'
|
import { getIdFilters } from '@welshman/util'
|
||||||
|
|
||||||
|
|
@ -81,8 +81,11 @@ addRoute('post', '/subscription/email', async (req: Request, res: Response) => {
|
||||||
res.json(result)
|
res.json(result)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// If the error is just Postmark failing, the subscription was still created
|
// If the error is just Postmark failing, the subscription was still created
|
||||||
if (error.message?.includes('APIKey')) {
|
// Look up the actual subscription key from the DB
|
||||||
res.json({ key: 'fallback', callback: `${process.env.BASE_URL}/notify/fallback` })
|
const sub = await getSubscriptionByPubkey(pubkey)
|
||||||
|
if (sub) {
|
||||||
|
const callback = `${process.env.BASE_URL}/notify/${sub.id}`
|
||||||
|
res.json({ key: sub.key, callback })
|
||||||
} else {
|
} else {
|
||||||
console.error('Failed to register subscription:', error)
|
console.error('Failed to register subscription:', error)
|
||||||
res.status(500).json({ error: 'Failed to register subscription' })
|
res.status(500).json({ error: 'Failed to register subscription' })
|
||||||
|
|
@ -180,7 +183,7 @@ addRoute('get', '/unsubscribe', async (req: Request, res: Response) => {
|
||||||
// pass
|
// 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) => {
|
server.use((err: Error, req: Request, res: Response, next: NextFunction) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue