generated from nhcarrigan/template
feat: separate token for errors, new url
This commit is contained in:
@@ -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"
|
||||
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/log_token"
|
||||
ERROR_LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/error_token"
|
||||
+33
-2
@@ -17,7 +17,7 @@ const priority: Record<string, number> = {
|
||||
* @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<void> => {
|
||||
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 };
|
||||
|
||||
+2
-2
@@ -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<void> => {
|
||||
`[ERROR]: ${context} - ${application}`,
|
||||
`${message}\n\n${stack}`,
|
||||
);
|
||||
await pipeLog(
|
||||
await pipeError(
|
||||
application,
|
||||
`${context} - ${message}\n${stack}`,
|
||||
"error",
|
||||
|
||||
Reference in New Issue
Block a user