This commit is contained in:
Philipp Dormann 2024-12-11 18:16:29 +01:00
parent 56ebf652b1
commit 642e141abd
Signed by: philipp
GPG Key ID: 3BB9ADD52DCA4314
3 changed files with 9 additions and 3 deletions

View File

@ -6,3 +6,4 @@ EMAIL_FROM="noreply@lauf-fuer-kaya.de"
EMAIL_REPLYTO="info@lauf-fuer-kaya.de"
REDIS_URL=redis://localhost:6379
FRONTEND_URL="https://run.lauf-fuer-kaya.de"
AUTHKEY=""

View File

@ -9,6 +9,10 @@ const app = new Hono()
app.use('*', logger())
app.use('*', prettyJSON())
if ((process.env.AUTHKEY || "") === "") {
console.warn("process.env.AUTHKEY was not provided!");
}
app.route('/api/v1/email', emailRouter)
app.get('/docs', createSwaggerUI())
app.get('/swagger', createSwaggerUI())

View File

@ -1,4 +1,5 @@
import { Hono } from 'hono'
import { bearerAuth } from 'hono/bearer-auth'
import { zValidator } from '@hono/zod-validator'
import { z } from 'zod'
import { EmailService } from '../services/email'
@ -32,7 +33,7 @@ async function generateBarcodeDataURL(data) {
return dataURL;
}
emailRouter.post('/', zValidator('json', sendEmailSchema), async (c) => {
emailRouter.post('/', bearerAuth({ token: process.env.AUTHKEY }),zValidator('json', sendEmailSchema), async (c) => {
let { to, templateName, language, data } = c.req.valid('json')
try {
@ -67,7 +68,7 @@ emailRouter.post('/', zValidator('json', sendEmailSchema), async (c) => {
})
// Add queue status endpoint
emailRouter.get('/status', async (c) => {
emailRouter.get('/status', bearerAuth({ token: process.env.AUTHKEY }),async (c) => {
try {
const status = await emailService.getQueueStatus()
return c.json(status)