API: Add experimental Json API

in preparation for external healthchecks and the
admin backend. We define a couple test routes:

- / List all routes
- /ping Replies pong for online-checks
- /stats Get high-level bot statistics
- /most-recent-drop Returns the most recent entry from dropHistories

The last two routes require a valid apikey header.
All routes are prefixed by /api/v1
This commit is contained in:
2023-04-05 12:00:46 +02:00
parent fdf5a4074b
commit f1e01f2a9f
6 changed files with 1181 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ require("dotenv").config();
const { Console } = require("console");
const fs = require("fs");
const {Client, GatewayIntentBits, Collection} = require("discord.js");
const webApi = require('./api/jsonApi');
const dbUtil = require("./util/db")
const logger = new Console({
@@ -44,6 +45,11 @@ logger.log("Syncing database...");
dbUtil.syncDb();
client.login(process.env.TOKEN);
webApi.client = client;
const PORT = process.env.API_PORT;
webApi.listen(PORT, () => {
console.log(`HTTP API listening on port ${PORT}`);
});