diff --git a/src/index.ts b/src/index.ts index 3ce7cc5..a0d3592 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,7 +29,7 @@ async function init() { log.nonsense('booting chip...'); log.nonsense('starting up web interface...'); - await startServer(sitePort); + await startServer(bot, sitePort); log.nonsense('setting up connection...'); diff --git a/src/web.ts b/src/web.ts index b2c625a..32326fb 100644 --- a/src/web.ts +++ b/src/web.ts @@ -2,8 +2,9 @@ import express from 'express'; import * as log from './lib/log'; import { CustomItem, db } from './lib/db'; import { defaultItems } from './lib/rpg/items'; +import { Client } from 'discord.js'; -export async function startServer(port: number) { +export async function startServer(bot: Client, port: number) { const app = express(); app.use(express.static('static/')); @@ -24,5 +25,12 @@ export async function startServer(port: number) { res.json([...defaultItems, ...customItems]); }); + app.get('/api/status', async (_, res) => { + res.json({ + guilds: bot.guilds.cache.size, + uptime: bot.uptime + }); + }); + app.listen(port, () => log.info(`web interface listening on ${port}`)); } \ No newline at end of file diff --git a/static/create-recipe/script.js b/static/create-recipe/script.js index 3b498a7..f705817 100644 --- a/static/create-recipe/script.js +++ b/static/create-recipe/script.js @@ -128,10 +128,10 @@ Promise.all([ fetch(`/api/items${document.location.search}`) .then(res => res.json()), loaded -]).then(items => { +]).then(([items]) => { const itemsContainer = document.querySelector('.items'); itemsContainer.textContent = ''; - items[0].forEach(item => + items.forEach(item => itemsContainer.appendChild(renderItem(item)) ); document.querySelectorAll('.item-list').forEach(elem => { diff --git a/static/index.html b/static/index.html index d4b4966..5283dc7 100644 --- a/static/index.html +++ b/static/index.html @@ -12,6 +12,8 @@ + +