Public Source Viewer
비나래아카이브 개발자 포털
실제 서비스 구조를 살펴볼 수 있는 공개용 코드 뷰어입니다. 인증, 세션, 외부 연동, 토큰, 관리자 식별 등 보안상 민감한 구현은 파일 단위 또는 줄 단위로 검열됩니다.
src/index.ts
공개 가능
1
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
2
3
import express, { Application } from 'express';
4
import favicon from 'serve-favicon';
5
import fs from 'fs';
6
import http from 'http';
7
import https from 'https';
8
import path from 'path';
9
import { Config } from './types/models';
10
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
11
import setupRoutes from './routes';
12
import { startDiscordBot } from './bot/discord-bot';
13
14
const app: Application = express();
15
16
const configFile: Config = require(path.join(CONFIG_DIR, 'config.json'));
17
18
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
19
const certPath = path.join(CERT_DIR, 'privkey.pem');
20
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
21
22
app.use('/vendors/bootstrap', express.static(path.join(NODE_MODULES_DIR, 'bootstrap/dist')));
23
app.use(express.static(PUBLIC_DIR));
24
app.set('views', VIEW_DIR);
25
app.set('view engine', 'ejs');
26
app.use(require('express-title')());
27
app.set('title', '비나래');
28
app.engine('html', require('ejs').renderFile);
29
app.use(express.static(VIEW_DIR));
30
app.use(favicon(path.join(VIEW_DIR, 'image/favicon.ico')));
31
32
// 날짜 포맷 헬퍼 미들웨어 (YYYY/MM/DD, HH:mm:ss)
33
app.use((req, res, next) => {
34
res.locals.fmtDate = (d: string | Date, short?: boolean) => {
35
const date = new Date(d);
36
const Y = date.getFullYear();
37
const M = String(date.getMonth() + 1).padStart(2, '0');
38
const D = String(date.getDate()).padStart(2, '0');
39
if (short) return `${Y}/${M}/${D}`;
40
const h = String(date.getHours()).padStart(2, '0');
41
const m = String(date.getMinutes()).padStart(2, '0');
42
const s = String(date.getSeconds()).padStart(2, '0');
43
return `${Y}/${M}/${D}, ${h}:${m}:${s}`;
44
};
45
next();
46
});
47
48
// Setup all routes
49
setupRoutes(app);
50
51
app.use((req, res) => {
52
res.status(404).send('<meta http-equiv="refresh" content="0; url=/hinana/ichikawa"></meta>');
53
});
54
55
const httpServer = http.createServer(hasCerts ? (() => {
56
const httpApp = express();
57
httpApp.use((req, res) => {
58
const host = req.headers.host?.replace(`:${configFile.Use_Port}`, `:${configFile.Use_SSH_Port}`) || `localhost:${configFile.Use_SSH_Port}`;
59
res.redirect(301, `https://${host}${req.url}`);
60
});
61
return httpApp;
62
})() : app);
63
64
if (hasCerts) {
65
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
66
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
67
const httpsServer = https.createServer({ key: privateKey, cert: certificate }, app);
68
httpsServer.listen(configFile.Use_SSH_Port, () => console.log(`HTTPS server listening on port ${configFile.Use_SSH_Port}`));
69
}
70
71
httpServer.listen(configFile.Use_Port, () => console.log(`HTTP server listening on port ${configFile.Use_Port}${hasCerts ? ' (redirects to HTTPS)' : ''}`));
72
73
// Discord 봇 시작
74
startDiscordBot();
75