+3
-2
src/commands/fun/trivia.ts
+3
-2
src/commands/fun/trivia.ts
···
485
485
try {
486
486
const channelId = interaction.channelId;
487
487
const clickMessageId = interaction.message?.id;
488
-
let session = (clickMessageId && gameManager.get(clickMessageId)) || gameManager.get(channelId);
488
+
let session =
489
+
(clickMessageId && gameManager.get(clickMessageId)) || gameManager.get(channelId);
489
490
const customId = interaction.customId;
490
491
491
492
if (!session && clickMessageId) {
492
-
for (const [key, s] of gameManager.entries()) {
493
+
for (const [, s] of gameManager.entries()) {
493
494
if (s.messageId === clickMessageId) {
494
495
session = s;
495
496
break;
+15
-3
src/index.ts
+15
-3
src/index.ts
···
2
2
import e from 'express';
3
3
import helmet from 'helmet';
4
4
import cors from 'cors';
5
+
import path from 'path';
6
+
import { fileURLToPath } from 'url';
5
7
6
8
import BotClient from './services/Client';
7
9
import { ALLOWED_ORIGINS, PORT, RATE_LIMIT_WINDOW_MS, RATE_LIMIT_MAX } from './config';
···
28
30
29
31
const app = e();
30
32
const startTime = Date.now();
33
+
const __filename = fileURLToPath(import.meta.url);
34
+
const __dirname = path.dirname(__filename);
35
+
const distPath = path.resolve(__dirname, '../web/dist');
31
36
32
37
app.use(helmet());
33
38
app.use(
···
80
85
const start = process.hrtime.bigint();
81
86
res.on('finish', () => {
82
87
const durMs = Number(process.hrtime.bigint() - start) / 1e6;
83
-
logger.info(`API [${req.method}] ${req.originalUrl} ${res.statusCode} ${durMs.toFixed(1)}ms`); // log the api request
88
+
const safePath = req.baseUrl ? `${req.baseUrl}${req.path}` : req.path;
89
+
logger.info(`API [${req.method}] ${safePath} ${res.statusCode} ${durMs.toFixed(1)}ms`);
84
90
});
85
91
next();
86
92
});
···
96
102
res.status(200).json({ status: 'ok', timestamp: new Date().toISOString() });
97
103
});
98
104
99
-
app.get('*', (req, res) => {
105
+
app.use(e.static(distPath, { index: false, maxAge: '1h' }));
106
+
107
+
app.get(/^\/(?!api\/).*/, (req, res) => {
108
+
return res.sendFile(path.join(distPath, 'index.html'));
109
+
});
110
+
111
+
app.use((req, res) => {
100
112
return res.status(404).json({ status: 404, message: 'Not Found' });
101
113
});
102
114
···
110
122
const server = app.listen(PORT, async () => {
111
123
logger.debug('Aethel is live on', `http://localhost:${PORT}`);
112
124
113
-
const { sendDeploymentNotification } = await import('./utils/sendDeploymentNotification');
125
+
const { sendDeploymentNotification } = await import('./utils/sendDeploymentNotification.js');
114
126
await sendDeploymentNotification(startTime);
115
127
});
116
128