From 2ac9157b0df53990407b5444162cbcb9e411e6bb Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Tue, 7 Oct 2025 11:56:39 -0700 Subject: [PATCH] feat: separate token for errors, new url --- prod.env | 3 ++- src/modules/pipeLog.ts | 35 +++++++++++++++++++++++++++++++++-- src/server/serve.ts | 4 ++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/prod.env b/prod.env index 38e299c..caf02b4 100644 --- a/prod.env +++ b/prod.env @@ -6,4 +6,5 @@ DISCORD_WEBHOOK_URL="op://Environment Variables - Naomi/Alert Server/discord_hoo STRIPE_SECRET_KEY="op://Environment Variables - Naomi/Alert Server/stripe" STRIPE_WEBHOOK_SECRET="op://Environment Variables - Naomi/Alert Server/stripe_webhook" DISCORD_TOKEN="op://Environment Variables - Naomi/Alert Server/discord_token" -LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/log_token" \ No newline at end of file +LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/log_token" +ERROR_LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/error_token" \ No newline at end of file diff --git a/src/modules/pipeLog.ts b/src/modules/pipeLog.ts index 61dd023..cc73dfd 100644 --- a/src/modules/pipeLog.ts +++ b/src/modules/pipeLog.ts @@ -17,7 +17,7 @@ const priority: Record = { * @param message - The message to log. * @param level - The level of the log, used for priority. */ -export const pipeLog = async( +const pipeLog = async( appName: string, message: string, level: string, @@ -26,7 +26,7 @@ export const pipeLog = async( if (logToken === undefined) { return; } - await fetch(`https://graylog.nhcarrigan.com/message?token=${logToken}`, { + await fetch(`https://logs.nhcarrigan.com/message?token=${logToken}`, { body: JSON.stringify({ message: message, priority: priority[level] ?? priority.debug, @@ -39,3 +39,34 @@ export const pipeLog = async( method: "POST", }); }; + +/** + * Pipes a log message to the Gotify server. + * @param appName - The name of the application. + * @param message - The message to log. + * @param level - The level of the log, used for priority. + */ +const pipeError = async( + appName: string, + message: string, + level: string, +): Promise => { + const logToken = process.env.ERROR_LOG_TOKEN; + if (logToken === undefined) { + return; + } + await fetch(`https://logs.nhcarrigan.com/message?token=${logToken}`, { + body: JSON.stringify({ + message: message, + priority: priority[level] ?? priority.debug, + title: appName, + }), + headers: { + // eslint-disable-next-line @typescript-eslint/naming-convention -- Standard header. + "Content-Type": "application/json", + }, + method: "POST", + }); +}; + +export { pipeError, pipeLog }; diff --git a/src/server/serve.ts b/src/server/serve.ts index cafa759..30f9f9e 100644 --- a/src/server/serve.ts +++ b/src/server/serve.ts @@ -10,7 +10,7 @@ import rawBody from "fastify-raw-body"; import StripeApp from "stripe"; import { applicationData } from "../config/applicationData.js"; import { auth } from "../modules/auth.js"; -import { pipeLog } from "../modules/pipeLog.js"; +import { pipeError, pipeLog } from "../modules/pipeLog.js"; import { sendMail } from "../modules/sendMail.js"; import { validateWebhook } from "../modules/validateWebhook.js"; import { errorSchema } from "../schemas/errorSchema.js"; @@ -108,7 +108,7 @@ export const instantiateServer = async(): Promise => { `[ERROR]: ${context} - ${application}`, `${message}\n\n${stack}`, ); - await pipeLog( + await pipeError( application, `${context} - ${message}\n${stack}`, "error",