Public Source Viewer

비나래아카이브 개발자 포털

실제 서비스 구조를 살펴볼 수 있는 공개용 코드 뷰어입니다. 인증, 세션, 외부 연동, 토큰, 관리자 식별 등 보안상 민감한 구현은 파일 단위 또는 줄 단위로 검열됩니다.

Redacted View
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 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
17 ? path.join(CONFIG_DIR, 'config.json')
18 : path.join(CONFIG_DIR, 'config.json.example');
19 const configFile: Config = require(configPath);
20
21 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
22 const certPath = path.join(CERT_DIR, 'privkey.pem');
23 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
24
25 app.use('/vendors/bootstrap', express.static(path.join(NODE_MODULES_DIR, 'bootstrap/dist')));
26 app.use(express.static(PUBLIC_DIR));
27 app.use('/image', express.static(path.join(VIEW_DIR, 'image')));
28 app.set('views', VIEW_DIR);
29 app.set('view engine', 'ejs');
30 app.use(require('express-title')());
31 app.set('title', '비나래');
32 app.engine('html', require('ejs').renderFile);
33 app.use(favicon(path.join(VIEW_DIR, 'image/favicon.ico')));
34
35 // 날짜 포맷 헬퍼 미들웨어 (YYYY/MM/DD, HH:mm:ss)
36 app.use((req, res, next) => {
37 res.locals.fmtDate = (d: string | Date, short?: boolean) => {
38 const date = new Date(d);
39 const Y = date.getFullYear();
40 const M = String(date.getMonth() + 1).padStart(2, '0');
41 const D = String(date.getDate()).padStart(2, '0');
42 if (short) return `${Y}/${M}/${D}`;
43 const h = String(date.getHours()).padStart(2, '0');
44 const m = String(date.getMinutes()).padStart(2, '0');
45 const s = String(date.getSeconds()).padStart(2, '0');
46 return `${Y}/${M}/${D}, ${h}:${m}:${s}`;
47 };
48 next();
49 });
50
51 // Setup all routes
52 setupRoutes(app);
53
54 app.use((req, res) => {
55 res.status(404).send('<meta http-equiv="refresh" content="0; url=/hinana/ichikawa"></meta>');
56 });
57
58 const httpServer = http.createServer(hasCerts ? (() => {
59 const httpApp = express();
60 httpApp.use((req, res) => {
61 const host = req.headers.host?.replace(`:${configFile.Use_Port}`, `:${configFile.Use_SSH_Port}`) || `localhost:${configFile.Use_SSH_Port}`;
62 res.redirect(301, `https://${host}${req.url}`);
63 });
64 return httpApp;
65 })() : app);
66
67 if (hasCerts) {
68 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
69 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
70 const httpsServer = https.createServer({ key: privateKey, cert: certificate }, app);
71 httpsServer.listen(configFile.Use_SSH_Port, () => console.log(`HTTPS server listening on port ${configFile.Use_SSH_Port}`));
72 }
73
74 httpServer.listen(configFile.Use_Port, () => console.log(`HTTP server listening on port ${configFile.Use_Port}${hasCerts ? ' (redirects to HTTPS)' : ''}`));
75
76 // Discord 봇 시작
77 startDiscordBot();
78