Public Source Viewer
비나래아카이브 개발자 포털
실제 서비스 구조를 살펴볼 수 있는 공개용 코드 뷰어입니다. 인증, 세션, 외부 연동, 토큰, 관리자 식별 등 보안상 민감한 구현은 파일 단위 또는 줄 단위로 검열됩니다.
src/routes/monitoring.routes.ts
공개 가능
1
import { Router, Request, Response } from 'express';
2
import { Settings } from '../types/models';
3
import { readSettings, writeSettings } from '../services/settings.service';
4
import { getMonitoringSnapshot } from '../services/monitoring.service';
5
import { recordSecurityLog } from '../services/security-log.service';
6
7
const router = Router();
8
9
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
10
const TOGGLE_KEYS: (keyof Settings)[] = [
11
'isSignupEnabled',
12
'isAnonymousPostingEnabled',
13
'isGptEnabled',
14
'isSubwayApiEnabled',
15
'isPushEnabled',
16
'isDiscordShareEnabled',
17
'isDiscordPersonaCommandEnabled',
18
'isDiscordAiCommandEnabled'
19
];
20
21
function requireAdmin(req: Request, res: Response, next: () => void): void {
22
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
23
return res.redirect('/hinana/lounge');
24
}
25
next();
26
}
27
28
router.get('/hinana/monitor', requireAdmin, (req: Request, res: Response) => {
29
res.render('./hinana/monitor', {
30
username: req.session.username,
31
theme: req.session.theme || req.cookies.theme || 'light',
32
snapshot: getMonitoringSnapshot()
33
});
34
});
35
36
router.get('/api/admin/monitoring', requireAdmin, (_req: Request, res: Response) => {
37
res.json({ success: true, snapshot: getMonitoringSnapshot() });
38
});
39
40
router.post('/api/admin/features/:key/toggle', requireAdmin, (req: Request, res: Response) => {
41
const key = req.params.key as keyof Settings;
42
if (!TOGGLE_KEYS.includes(key)) {
43
return res.status(400).json({ success: false, message: 'Unknown feature flag' });
44
}
45
46
const settings = readSettings();
47
const nextValue = !(settings[key] !== false);
48
(settings as any)[key] = nextValue;
49
writeSettings(settings);
50
51
recordSecurityLog(req, {
52
type: 'admin_action',
53
action: `Feature flag changed: ${String(key)}`,
54
detail: nextValue ? 'enabled' : 'disabled'
55
});
56
57
res.json({ success: true, key, enabled: nextValue, snapshot: getMonitoringSnapshot() });
58
});
59
60
export default router;
61