generated from nhcarrigan/template
feat: add health check server
This commit is contained in:
parent
9def06d149
commit
6bfe251fe7
@ -12,7 +12,7 @@
|
|||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "20",
|
"node": "20",
|
||||||
"pnpm": "8"
|
"pnpm": "9"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -43,6 +43,7 @@
|
|||||||
"@sentry/node": "7.114.0",
|
"@sentry/node": "7.114.0",
|
||||||
"discord.js": "14.15.2",
|
"discord.js": "14.15.2",
|
||||||
"dotenv": "16.4.5",
|
"dotenv": "16.4.5",
|
||||||
|
"fastify": "5.0.0",
|
||||||
"winston": "3.13.0"
|
"winston": "3.13.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2920
pnpm-lock.yaml
generated
2920
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@ import * as Sentry from "@sentry/node";
|
|||||||
import { Client, GatewayIntentBits, WebhookClient } from "discord.js";
|
import { Client, GatewayIntentBits, WebhookClient } from "discord.js";
|
||||||
|
|
||||||
import { manageRoles } from "./modules/manageRoles";
|
import { manageRoles } from "./modules/manageRoles";
|
||||||
|
import { instantiateServer } from "./server/serve";
|
||||||
import { errorHandler } from "./utils/errorHandler";
|
import { errorHandler } from "./utils/errorHandler";
|
||||||
|
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
@ -43,6 +44,7 @@ Sentry.init({
|
|||||||
});
|
});
|
||||||
|
|
||||||
await bot.login(process.env.DISCORD_TOKEN);
|
await bot.login(process.env.DISCORD_TOKEN);
|
||||||
|
await instantiateServer(bot);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await errorHandler("index", err);
|
await errorHandler("index", err);
|
||||||
}
|
}
|
||||||
|
48
src/server/serve.ts
Normal file
48
src/server/serve.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { readFile } from "fs/promises";
|
||||||
|
|
||||||
|
import { type Client, WebhookClient } from "discord.js";
|
||||||
|
import fastify from "fastify";
|
||||||
|
|
||||||
|
import { errorHandler } from "../utils/errorHandler";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts up a web server for health monitoring.
|
||||||
|
*
|
||||||
|
* @param {Client} bot The bot's Discord instance.
|
||||||
|
*/
|
||||||
|
export const instantiateServer = async (bot: Client) => {
|
||||||
|
try {
|
||||||
|
const server = fastify({
|
||||||
|
logger: false,
|
||||||
|
https: {
|
||||||
|
cert: await readFile(
|
||||||
|
"/etc/letsencrypt/live/oogie.nhcarrigan.com-0001/cert.pem"
|
||||||
|
),
|
||||||
|
key: await readFile(
|
||||||
|
"/etc/letsencrypt/live/oogie.nhcarrigan.com-0001/privkey.pem"
|
||||||
|
),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
server.get("/", (_req, res) => {
|
||||||
|
res.send("Health check~!");
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen({ port: 1443 }, (err) => {
|
||||||
|
if (err) {
|
||||||
|
void errorHandler("start server", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hook = new WebhookClient({ url: process.env.DEBUG_HOOK as string });
|
||||||
|
void hook.send({
|
||||||
|
avatarURL:
|
||||||
|
bot.user?.displayAvatarURL() ??
|
||||||
|
"https://cdn.nhcarrigan.com/profile.png",
|
||||||
|
content: "Fastify server live on port 1443~!",
|
||||||
|
username: bot.user?.username ?? "Hacktoberfest",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
await errorHandler("instantiate server", err);
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user