Skip to content

Commit

Permalink
Make /notification auth false & some misc amends
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmidrahman-dsi committed Apr 5, 2024
1 parent 527540b commit 37aa758
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 48 deletions.
4 changes: 3 additions & 1 deletion infrastructure/docker-compose.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ services:
deploy:
labels:
- 'traefik.enable=true'
- 'traefik.http.routers.countryconfig.rule=Host(`countryconfig.{{hostname}}`) && !Path(`/email`)'
- 'traefik.http.routers.countryconfig.rule=Host(`countryconfig.{{hostname}}`) && !Path(`/email`) && !Path(`/notification`)'
- 'traefik.http.services.countryconfig.loadbalancer.server.port=3040'
- 'traefik.http.routers.countryconfig.tls=true'
- 'traefik.http.routers.countryconfig.tls.certresolver=certResolver'
Expand All @@ -573,6 +573,8 @@ services:
- 'traefik.http.middlewares.block-email.ipwhitelist.sourcerange=255.255.255.255'
- 'traefik.http.routers.block-email.rule=Host(`countryconfig.{{hostname}}`) && Path(`/email`)'
- 'traefik.http.routers.block-email.middlewares=block-email'
- 'traefik.http.routers.block-notification.rule=Host(`countryconfig.{{hostname}}`) && Path(`/notification`)'
- 'traefik.http.routers.block-notification.middlewares=block-email'
replicas: 1
environment:
- MONGO_URL=mongodb://mongo1/user-mgnt?replicaSet=rs0
Expand Down
45 changes: 0 additions & 45 deletions src/api/notification/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,48 +167,3 @@ export async function emailHandler(

return h.response().code(200)
}

interface MassEmailPayload {
subject: string
body: string
bcc: string[]
}

export const massEmailSchema = Joi.object({
subject: Joi.string().required(),
body: Joi.string().required(),
bcc: Joi.array().items(Joi.string())
})

export async function massEmailHandler(
request: Hapi.Request,
h: Hapi.ResponseToolkit
) {
const { bcc, ...variables } = request.payload as MassEmailPayload
if (process.env.NODE_ENV !== 'production') {
logger.info(
`Ignoring email due to NODE_ENV not being 'production'. Params: ${JSON.stringify(
variables
)}`
)
return h.response().code(200)
}

logger.info(`Emails are being sent to ${bcc[0]}...${bcc[bcc.length - 1]}`)

const template = getTemplate('allUserNotification')
const emailbody = renderTemplate(template, {
...variables,
countryLogo: COUNTRY_LOGO_URL
})

await sendEmail({
...variables,
to: bcc[0],
from: SENDER_EMAIL_ADDRESS,
bcc: bcc.slice(1),
html: emailbody
})

return h.response().code(200)
}
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ import { logger } from '@countryconfig/logger'
import {
emailHandler,
emailSchema,
massEmailHandler,
massEmailSchema,
notificationHandler,
notificationSchema
} from './api/notification/handler'
Expand Down Expand Up @@ -454,6 +452,7 @@ export async function createServer() {
handler: notificationHandler,
options: {
tags: ['api'],
auth: false,
validate: {
payload: notificationSchema
},
Expand Down

0 comments on commit 37aa758

Please sign in to comment.