-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
659 lines (593 loc) · 22.6 KB
/
Copy pathserver.js
File metadata and controls
659 lines (593 loc) · 22.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import * as db from './data.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const PORT = process.env.PORT || 3000;
// Redirect from mottaero to meottaero
app.use((req, res, next) => {
const host = req.get('host') || '';
if (host.includes('mottaero')) {
const newHost = host.replace('mottaero', 'meottaero');
return res.redirect(301, `https://${newHost}${req.originalUrl}`);
}
next();
});
// Set up template engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// Serve static assets with caching headers for media
app.use(express.static(path.join(__dirname, 'public'), {
setHeaders: (res, filePath) => {
if (filePath.endsWith('.mp4') || filePath.endsWith('.jpg') || filePath.endsWith('.jpeg') || filePath.endsWith('.png')) {
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
}
}
}));
// Parse JSON and form request bodies (with larger limit for photo booth base64 uploads)
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ limit: '10mb', extended: true }));
// Middleware to inject active page and database helpers to templates
app.use((req, res, next) => {
res.locals.activeMenu = '';
res.locals.db = db;
next();
});
// Route: Home Page
app.get('/', (req, res) => {
const initialProject = db.getRandomProject();
const initialStudent = initialProject ? db.getStudent(initialProject.studentId) : null;
res.render('home', {
title: '// MEOTTAERO',
activeMenu: 'home',
initialProject,
initialStudent
});
});
// Route: Projects Page (Semester list)
app.get('/projects', (req, res) => {
const initialProject = db.getRandomProject();
const initialStudent = initialProject ? db.getStudent(initialProject.studentId) : null;
const semesters = db.getSemesters();
res.render('projects', {
title: '// MEOTTAERO',
activeMenu: 'projects',
semesters,
initialProject,
initialStudent
});
});
// Route: Specific Semester (Projects in that semester)
app.get('/projects/:semester_id', async (req, res) => {
const semesterId = req.params.semester_id;
const semester = db.getSemester(semesterId);
if (!semester) {
return res.status(404).send('Semester not found');
}
const semesters = db.getSemesters();
const projects = db.getProjectsBySemester(semesterId);
let isSoldOut = false;
try {
const capacities = await db.getCapacities();
const bookings = await db.getBookings();
if (semesterId === 'the-sia-vol-2') {
const siaCount = bookings.filter(b => {
let eventId = '춤출자유vol-2';
if (b.studentId) {
if (b.studentId.includes('10대') || b.studentId.includes('20대') || b.studentId.includes('30대') || b.studentId.includes('40대') || b.studentId.includes('50대') || b.studentId.includes('60대')) {
eventId = '다놀다농';
} else if (b.studentId.includes('참가') || b.studentId.includes('관람')) {
eventId = 'the-sia-vol-2';
}
}
return eventId === 'the-sia-vol-2';
}).length;
const maxCapacity = capacities['the-sia-vol-2'] !== undefined ? capacities['the-sia-vol-2'] : 150;
isSoldOut = siaCount >= maxCapacity;
} else if (semesterId === '다놀다농') {
const danongCount = bookings.filter(b => {
let eventId = '춤출자유vol-2';
if (b.studentId) {
if (b.studentId.includes('10대') || b.studentId.includes('20대') || b.studentId.includes('30대') || b.studentId.includes('40대') || b.studentId.includes('50대') || b.studentId.includes('60대')) {
eventId = '다놀다농';
} else if (b.studentId.includes('참가') || b.studentId.includes('관람')) {
eventId = 'the-sia-vol-2';
}
}
return eventId === '다놀다농';
}).length;
const maxCapacity = capacities['다놀다농'] !== undefined ? capacities['다놀다농'] : 50;
isSoldOut = danongCount >= maxCapacity;
}
} catch (error) {
console.error('Error calculating isSoldOut in GET /projects/:semester_id:', error);
}
res.render('semester', {
title: `// MEOTTAERO — ${semester.title}`,
activeMenu: 'projects',
semesters,
activeSemester: semester,
projects,
isSoldOut
});
});
// Route: Crew Page
app.get('/crew', (req, res) => {
const initialProject = db.getRandomProject();
const initialStudent = initialProject ? db.getStudent(initialProject.studentId) : null;
const students = db.getStudents();
res.render('crew', {
title: '// MEOTTAERO',
activeMenu: 'crew',
students,
initialProject,
initialStudent
});
});
// Route: Specific Crew Member Page (Crew member details and their projects list)
app.get('/crew/:student_id', (req, res) => {
const studentId = req.params.student_id;
const student = db.getStudent(studentId);
if (!student) {
return res.status(404).send('Crew member not found');
}
const students = db.getStudents();
const projects = db.getProjectsByStudent(studentId);
res.render('crew_member', {
title: `// MEOTTAERO — ${student.name}`,
activeMenu: 'crew',
students,
activeStudent: student,
projects
});
});
// Route: Project Details from Crew Context
app.get('/crew/:student_id/:project_slug', (req, res) => {
const { student_id, project_slug } = req.params;
const student = db.getStudent(student_id);
const project = db.getProjectBySlug(student_id, project_slug);
if (!student || !project) {
return res.status(404).send('Project not found');
}
const semester = db.getSemester(project.semesterId);
const siblingProjects = db.getProjectsByStudent(student_id);
res.render('project_detail', {
title: `// MEOTTAERO — ${student.name} — ${project.title}`,
activeMenu: 'crew',
context: 'student',
student,
project,
semester,
siblingProjects
});
});
// Route: Project Details from Semester Context
app.get('/projects/:semester_id/:project_slug', (req, res) => {
const { semester_id, project_slug } = req.params;
const semester = db.getSemester(semester_id);
// Find project by slug and semesterId
const project = db.getProjects().find(p => p.semesterId === semester_id && p.slug === project_slug);
if (!semester || !project) {
return res.status(404).send('Project not found');
}
const student = db.getStudent(project.studentId);
const siblingProjects = db.getProjectsBySemester(semester_id);
res.render('project_detail', {
title: `// MEOTTAERO — ${student.name} — ${project.title}`,
activeMenu: 'projects',
context: 'semester',
student,
project,
semester,
siblingProjects
});
});
// Route: About Page
app.get('/about', (req, res) => {
res.render('about', {
title: '// MEOTTAERO — About',
activeMenu: 'about'
});
});
// Route: Play Page (Soundboard / Sequencer)
app.get('/play', (req, res) => {
res.render('play', {
title: '// MEOTTAERO — Play',
activeMenu: 'play'
});
});
// Route: Leaked Wiki Page (Deep Web style)
app.get('/wiki', (req, res) => {
res.render('wiki', {
title: '// MEOTTAERO — Hidden Mainframe',
activeMenu: 'wiki'
});
});
// Route: Photo Booth Page
app.get('/booth', (req, res) => {
res.render('booth', {
title: '// MEOTTAERO — Booth',
activeMenu: 'booth'
});
});
// Route: HETEROTOPIA Hidden Guestbook Page
app.get(['/HETEROTOPIA', '/heterotopia'], (req, res) => {
res.render('heterotopia', {
title: '⟪방주: HETEROTOPIA⟫',
activeMenu: 'heterotopia'
});
});
// Route: SIDANCE ✕ FUTURE YOU Interactive Media Art Installation
app.get(['/sidance', '/SIDANCE'], (req, res) => {
res.render('sidance', {
title: '// SIDANCE — FUTURE YOU',
activeMenu: 'sidance'
});
});
// Route: HETEROTOPIA Live Stream Page
app.get(['/HETEROTOPIA/stream', '/heterotopia/stream', '/stream', '/live'], (req, res) => {
res.render('stream', {
title: '⟪방주: HETEROTOPIA — STREAM⟫',
activeMenu: 'stream'
});
});
// Route: HETEROTOPIA Archive Page (#1 ~ #N feed)
app.get(['/HETEROTOPIA/archive', '/heterotopia/archive', '/archive'], (req, res) => {
res.render('archive', {
title: '⟪방주: HETEROTOPIA — GUESTBOOK⟫',
activeMenu: 'heterotopia'
});
});
// API: Get Heterotopia Cards
app.get('/api/heterotopia/cards', async (req, res) => {
try {
const cards = await db.getHeterotopiaCards();
res.json({ success: true, cards });
} catch (err) {
console.error('Error in GET /api/heterotopia/cards:', err);
res.status(500).json({ error: err.message });
}
});
// API: Save New Heterotopia Card
app.post('/api/heterotopia/cards', async (req, res) => {
try {
const cardData = req.body;
if (!cardData.text && !cardData.photo) {
return res.status(400).json({ error: '텍스트나 사진 중 하나는 작성해 주세요.' });
}
const newCard = await db.saveHeterotopiaCard(cardData);
res.json({ success: true, card: newCard });
} catch (err) {
console.error('Error in POST /api/heterotopia/cards:', err);
res.status(500).json({ error: err.message });
}
});
// API: Update Card Position after drag
app.patch('/api/heterotopia/cards/:id/position', async (req, res) => {
try {
const { id } = req.params;
const { x, y } = req.body;
await db.updateHeterotopiaCardPosition(id, x, y);
res.json({ success: true });
} catch (err) {
console.error('Error updating card position:', err);
res.status(500).json({ error: err.message });
}
});
// API: Exhibition Venue Broadcast Frame Upload
app.post('/api/stream/broadcast', async (req, res) => {
const { image } = req.body || {};
if (image) {
await db.saveLiveStreamFrame(image);
return res.json({ success: true });
}
res.status(400).json({ error: 'No image frame provided' });
});
// API: Visitor Fetch Live Exhibition Video Stream
app.get('/api/stream/live', async (req, res) => {
const info = await db.getLiveStreamFrame();
res.json({
success: true,
...info
});
});
// Route: API Upload to Supabase Storage
app.post('/api/booth/upload', async (req, res) => {
const { image } = req.body;
if (!image) {
return res.status(400).json({ error: 'No image data provided' });
}
try {
const base64Data = image.replace(/^data:image\/\w+;base64,/, "");
const buffer = Buffer.from(base64Data, 'base64');
// Generate KST (Korea Standard Time) filename: meottaero_YYYYMMDD_HHMMSS.jpg
const date = new Date();
const utc = date.getTime() + (date.getTimezoneOffset() * 60000);
const kst = new Date(utc + (9 * 3600000));
const yyyy = kst.getFullYear();
const mm = String(kst.getMonth() + 1).padStart(2, '0');
const dd = String(kst.getDate()).padStart(2, '0');
const hh = String(kst.getHours()).padStart(2, '0');
const min = String(kst.getMinutes()).padStart(2, '0');
const ss = String(kst.getSeconds()).padStart(2, '0');
const fileName = `meottaero_${yyyy}${mm}${dd}_${hh}${min}${ss}.jpg`;
const result = await db.uploadBoothPhoto(fileName, buffer);
if (result.success) {
return res.json({ success: true, path: result.path });
} else {
return res.status(500).json({ error: result.error });
}
} catch (err) {
console.error('Booth upload route error:', err);
return res.status(500).json({ error: err.message });
}
});
function formatPhone(phoneStr) {
if (!phoneStr) return '';
const nums = phoneStr.replace(/[^0-9]/g, '');
if (nums.length <= 3) return nums;
if (nums.length <= 7) return `${nums.slice(0, 3)}-${nums.slice(3)}`;
if (nums.length <= 11) return `${nums.slice(0, 3)}-${nums.slice(3, nums.length - 4)}-${nums.slice(nums.length - 4)}`;
return `${nums.slice(0, 3)}-${nums.slice(3, 7)}-${nums.slice(7, 11)}`;
}
function isValidPhone(phoneStr) {
if (!phoneStr) return false;
const nums = phoneStr.replace(/[^0-9]/g, '');
const mobileRegex = /^01[016789]\d{7,8}$/;
const landlineRegex = /^0(2|[3-6][1-5])\d{7,8}$/;
return mobileRegex.test(nums) || landlineRegex.test(nums);
}
// Route: POST Booking Form
app.post('/projects/:semesterId/book', async (req, res) => {
const { semesterId } = req.params;
try {
const capacities = await db.getCapacities();
const bookings = await db.getBookings();
if (semesterId === 'the-sia-vol-2') {
const count = bookings.filter(b => {
let eventId = '춤출자유vol-2';
if (b.studentId) {
if (b.studentId.includes('10대') || b.studentId.includes('20대') || b.studentId.includes('30대') || b.studentId.includes('40대') || b.studentId.includes('50대') || b.studentId.includes('60대')) {
eventId = '다놀다농';
} else if (b.studentId.includes('참가') || b.studentId.includes('관람')) {
eventId = 'the-sia-vol-2';
}
}
return eventId === 'the-sia-vol-2';
}).length;
const maxCapacity = capacities['the-sia-vol-2'] !== undefined ? capacities['the-sia-vol-2'] : 150;
if (count >= maxCapacity) {
return res.status(400).json({ error: '예매가 마감되었습니다.' });
}
const { name, phone, type, genre } = req.body;
if (!name || !phone || !type || !genre) {
return res.status(400).json({ error: '모든 필드를 올바르게 입력해 주세요.' });
}
if (!isValidPhone(phone)) {
return res.status(400).json({ error: '올바른 전화번호 형식(예: 010-1234-5678)으로 입력해 주세요.' });
}
const formattedPhone = formatPhone(phone);
const studentId = `${type} / ${genre}`;
const newBooking = await db.saveBooking({ name, studentId, phone: formattedPhone, tickets: 1 });
return res.json({ success: true, booking: newBooking });
}
if (semesterId === '다놀다농') {
const count = bookings.filter(b => {
let eventId = '춤출자유vol-2';
if (b.studentId) {
if (b.studentId.includes('10대') || b.studentId.includes('20대') || b.studentId.includes('30대') || b.studentId.includes('40대') || b.studentId.includes('50대') || b.studentId.includes('60대')) {
eventId = '다놀다농';
} else if (b.studentId.includes('참가') || b.studentId.includes('관람')) {
eventId = 'the-sia-vol-2';
}
}
return eventId === '다놀다농';
}).length;
const maxCapacity = capacities['다놀다농'] !== undefined ? capacities['다놀다농'] : 50;
if (count >= maxCapacity) {
return res.status(400).json({ error: '예매가 마감되었습니다.' });
}
const { name, phone, ageGroup, residence, referral, sessions } = req.body;
if (!name || !phone || !ageGroup || !residence || !referral || !sessions || !Array.isArray(sessions) || sessions.length === 0) {
return res.status(400).json({ error: '모든 필드를 올바르게 입력하고 신청 회차를 최소 하나 이상 선택해 주세요.' });
}
if (!isValidPhone(phone)) {
return res.status(400).json({ error: '올바른 전화번호 형식(예: 010-1234-5678)으로 입력해 주세요.' });
}
const formattedPhone = formatPhone(phone);
const studentId = `${ageGroup} / ${residence} / ${referral} / ${sessions.join(', ')}`;
const newBooking = await db.saveBooking({ name, studentId, phone: formattedPhone, tickets: 1 });
return res.json({ success: true, booking: newBooking });
}
} catch (error) {
console.error(`Error in POST /projects/${semesterId}/book:`, error);
return res.status(500).json({ error: '예매 처리 중 서버 오류가 발생했습니다.' });
}
return res.status(400).json({ error: '예매가 마감되었습니다.' });
});
// Auth middleware for admin routes (cookie-based)
function requireAdminAuth(req, res, next) {
const cookies = req.headers.cookie ? Object.fromEntries(req.headers.cookie.split(';').map(c => c.trim().split('='))) : {};
if (cookies.admin_session !== 'true') {
return res.redirect('/login');
}
next();
}
// Route: Admin Login Page (GET)
app.get('/login', (req, res) => {
res.render('login');
});
// Route: Admin Login Submit (POST)
app.post('/login', (req, res) => {
const { password } = req.body;
if (password === (process.env.ADMIN_PASSWORD || 'admin')) {
res.cookie('admin_session', 'true', { httpOnly: true, path: '/' });
return res.redirect('/admin');
}
res.render('login', { error: '비밀번호가 올바르지 않습니다.' });
});
// Route: Admin Bookings Dashboard
app.get('/admin', requireAdminAuth, async (req, res) => {
try {
let bookings = await db.getBookings();
bookings = bookings.map(b => {
let eventId = '춤출자유vol-2';
if (b.studentId) {
if (b.studentId.includes('10대') || b.studentId.includes('20대') || b.studentId.includes('30대') || b.studentId.includes('40대') || b.studentId.includes('50대') || b.studentId.includes('60대')) {
eventId = '다놀다농';
} else if (b.studentId.includes('참가') || b.studentId.includes('관람')) {
eventId = 'the-sia-vol-2';
}
}
return { ...b, eventId };
});
// Filter out bookings that belong to inactive/ended events
bookings = bookings.filter(b => b.eventId === 'the-sia-vol-2');
const capacities = await db.getCapacities();
res.render('bookings', {
title: '// MEOTTAERO — Admin Dashboard',
activeMenu: 'admin',
bookings,
capacities
});
} catch (error) {
console.error('Error in GET /admin:', error);
res.status(500).send('대시보드를 로드하는 중 오류가 발생했습니다.');
}
});
// Route: Admin redirect (backward compatibility for old path)
app.get('/admin/bookings', (req, res) => {
res.redirect('/admin');
});
// Route: Export Bookings as CSV
app.get('/admin/export', requireAdminAuth, async (req, res) => {
try {
let bookings = await db.getBookings();
const { event } = req.query;
// Classify bookings
bookings = bookings.map(b => {
let eventId = '춤출자유vol-2';
if (b.studentId) {
if (b.studentId.includes('10대') || b.studentId.includes('20대') || b.studentId.includes('30대') || b.studentId.includes('40대') || b.studentId.includes('50대') || b.studentId.includes('60대')) {
eventId = '다놀다농';
} else if (b.studentId.includes('참가') || b.studentId.includes('관람')) {
eventId = 'the-sia-vol-2';
}
}
return { ...b, eventId };
});
// Filter if requested, otherwise exclude inactive events by default
if (event && event !== 'all') {
bookings = bookings.filter(b => b.eventId === event);
} else {
bookings = bookings.filter(b => b.eventId === 'the-sia-vol-2');
}
const formatKST = (dateStr) => {
if (!dateStr) return '';
const d = new Date(dateStr);
if (isNaN(d.getTime())) return dateStr;
try {
return new Intl.DateTimeFormat('sv-SE', {
timeZone: 'Asia/Seoul',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
}).format(d).replace(/-/g, '.');
} catch (e) {
return dateStr;
}
};
const headers = ['공연', '이름', '구분 (학번/참가)', '연락처', '예매일시 (KST)'];
const rows = bookings.map(b => [
b.eventId === 'the-sia-vol-2' ? 'THE SIA Vol.2' : (b.eventId === '다놀다농' ? '다놀다농' : '춤 출 자유 Vol.2'),
b.name,
b.studentId,
b.phone,
formatKST(b.createdAt)
]);
const csv = [headers, ...rows]
.map(row => row.map(v => `"${String(v).replace(/"/g, '""')}"`).join(','))
.join('\n');
res.setHeader('Content-Type', 'text/csv; charset=utf-8');
const filename = event && event !== 'all' ? `bookings_${event}.csv` : 'bookings_all.csv';
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
res.send('' + csv);
} catch (error) {
console.error('Error in GET /admin/export:', error);
res.status(500).send('내보내기 중 오류가 발생했습니다.');
}
});
// Route: Update Booking Status (Admin Action)
app.post('/admin/update-status', requireAdminAuth, async (req, res) => {
const { code, paymentConfirmed, smsSent } = req.body;
if (!code) {
return res.status(400).json({ error: '예매 코드가 필요합니다.' });
}
try {
const success = await db.updateBookingStatus(code, { paymentConfirmed, smsSent });
if (success) {
res.json({ success: true });
} else {
res.status(404).json({ error: '예매 내역을 찾을 수 없습니다.' });
}
} catch (error) {
console.error('Error in POST /admin/update-status:', error);
res.status(500).json({ error: '상태 업데이트 중 서버 오류가 발생했습니다.' });
}
});
// Route: Update Booking Capacity Settings (Admin Action)
app.post('/admin/update-capacity', requireAdminAuth, async (req, res) => {
const { capacities } = req.body;
if (!capacities || typeof capacities !== 'object') {
return res.status(400).json({ error: '올바른 설정 데이터가 필요합니다.' });
}
try {
await db.saveCapacities(capacities);
res.json({ success: true });
} catch (error) {
console.error('Error in POST /admin/update-capacity:', error);
res.status(500).json({ error: '인원 제한 설정 저장 중 서버 오류가 발생했습니다.' });
}
});
// Route: DELETE Booking (Admin Action)
app.post('/admin/delete', requireAdminAuth, async (req, res) => {
const { code, password } = req.body;
if (!code) {
return res.status(400).json({ error: '예매 코드가 필요합니다.' });
}
// Verify the admin password
const adminPassword = process.env.ADMIN_PASSWORD || 'admin';
if (password !== adminPassword) {
return res.status(403).json({ error: '비밀번호가 올바르지 않습니다.' });
}
try {
const success = await db.deleteBooking(code);
if (success) {
res.json({ success: true });
} else {
res.status(404).json({ error: '예매 내역을 찾을 수 없습니다.' });
}
} catch (error) {
console.error('Error in POST /admin/delete:', error);
res.status(500).json({ error: '취소 처리 중 서버 오류가 발생했습니다.' });
}
});
// 404 Error Handler (Catch-all for unmatched routes)
app.use((req, res, next) => {
res.status(404).render('404', {
title: '// MEOTTAERO — 404',
activeMenu: '404'
});
});
// Export app for serverless environments (Vercel)
export default app;
// Start Server locally
if (process.env.NODE_ENV !== 'production') {
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server is running at http://localhost:${PORT}`);
});
}