import express from 'express'; import * as log from './lib/log'; import { CustomItem, db } from './lib/db'; import { defaultItems } from './lib/rpg/items'; export async function startServer(port: number) { const app = express(); app.use(express.static('static/')); app.get('/api/items', async (req, res) => { const guildID = req.query.guild; let customItems : Partial[]; if (guildID) { customItems = await db('customItems') .select('emoji', 'name', 'id', 'description') .where('guild', guildID) .limit(25); } else { customItems = []; } res.json([...defaultItems, ...customItems]); }); app.listen(port, () => log.info(`web interface listening on ${port}`)); }