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_SECRET_KEY="op://Environment Variables - Naomi/Alert Server/stripe"
|
||||||
STRIPE_WEBHOOK_SECRET="op://Environment Variables - Naomi/Alert Server/stripe_webhook"
|
STRIPE_WEBHOOK_SECRET="op://Environment Variables - Naomi/Alert Server/stripe_webhook"
|
||||||
DISCORD_TOKEN="op://Environment Variables - Naomi/Alert Server/discord_token"
|
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 message - The message to log.
|
||||||
* @param level - The level of the log, used for priority.
|
* @param level - The level of the log, used for priority.
|
||||||
*/
|
*/
|
||||||
export const pipeLog = async(
|
const pipeLog = async(
|
||||||
appName: string,
|
appName: string,
|
||||||
message: string,
|
message: string,
|
||||||
level: string,
|
level: string,
|
||||||
@@ -26,7 +26,7 @@ export const pipeLog = async(
|
|||||||
if (logToken === undefined) {
|
if (logToken === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await fetch(`https://graylog.nhcarrigan.com/message?token=${logToken}`, {
|
await fetch(`https://logs.nhcarrigan.com/message?token=${logToken}`, {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
message: message,
|
message: message,
|
||||||
priority: priority[level] ?? priority.debug,
|
priority: priority[level] ?? priority.debug,
|
||||||
@@ -39,3 +39,34 @@ export const pipeLog = async(
|
|||||||
method: "POST",
|
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 StripeApp from "stripe";
|
||||||
import { applicationData } from "../config/applicationData.js";
|
import { applicationData } from "../config/applicationData.js";
|
||||||
import { auth } from "../modules/auth.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 { sendMail } from "../modules/sendMail.js";
|
||||||
import { validateWebhook } from "../modules/validateWebhook.js";
|
import { validateWebhook } from "../modules/validateWebhook.js";
|
||||||
import { errorSchema } from "../schemas/errorSchema.js";
|
import { errorSchema } from "../schemas/errorSchema.js";
|
||||||
@@ -108,7 +108,7 @@ export const instantiateServer = async(): Promise<void> => {
|
|||||||
`[ERROR]: ${context} - ${application}`,
|
`[ERROR]: ${context} - ${application}`,
|
||||||
`${message}\n\n${stack}`,
|
`${message}\n\n${stack}`,
|
||||||
);
|
);
|
||||||
await pipeLog(
|
await pipeError(
|
||||||
application,
|
application,
|
||||||
`${context} - ${message}\n${stack}`,
|
`${context} - ${message}\n${stack}`,
|
||||||
"error",
|
"error",
|
||||||
|
|||||||
Reference in New Issue
Block a user