Skip to content

Commit

Permalink
refactor: printConfirmSubscription span
Browse files Browse the repository at this point in the history
  • Loading branch information
KishenKumarrrrr committed Nov 22, 2024
1 parent 566e538 commit 2fd482d
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions backend/src/email/middlewares/email-callback.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,28 @@ const printConfirmSubscription = (
res: Response,
next: NextFunction
): Response | void => {
tracer.wrap('printConfirmSubscription', () => {
const { Type: type, SubscribeURL: subscribeUrl } = JSON.parse(req.body)
if (type === 'SubscriptionConfirmation') {
const parsed = new URL(subscribeUrl)
if (
parsed.protocol === 'https:' &&
/^sns\.[a-zA-Z0-9-]{3,}\.amazonaws\.com(\.cn)?$/.test(parsed.host)
) {
logger.info({
message: 'Confirm the subscription',
type,
subscribeUrl,
action: 'printConfirmSubscription',
})
return res.sendStatus(202)
}
const printConfirmSubscriptionSpan = tracer.startSpan(
'printConfirmSubscription'
)
const { Type: type, SubscribeURL: subscribeUrl } = JSON.parse(req.body)
if (type === 'SubscriptionConfirmation') {
const parsed = new URL(subscribeUrl)
if (
parsed.protocol === 'https:' &&
/^sns\.[a-zA-Z0-9-]{3,}\.amazonaws\.com(\.cn)?$/.test(parsed.host)
) {
logger.info({
message: 'Confirm the subscription',
type,
subscribeUrl,
action: 'printConfirmSubscription',
})

return res.sendStatus(202)
}
return next()
})
}
printConfirmSubscriptionSpan.finish()
return next()
}
export const EmailCallbackMiddleware = {
isAuthenticated,
Expand Down

0 comments on commit 2fd482d

Please sign in to comment.