const express = require('express'); const path = require('path'); const app = express(); const PORT = process.env.PORT || 3000; app.use(express.json()); app.use(express.static(path.join(__dirname, 'public'))); // API routes app.get('/api/greeting', (req, res) => { const greetings = [ '안녕하세요! 👋', '반갑습니다! 😊', '어서오세요! 🌸', '좋은 하루예요! ☀️', '환영합니다! 🎉', ]; const message = greetings[Math.floor(Math.random() * greetings.length)]; res.json({ message }); }); app.get('/api/stats', (req, res) => { res.json({ uptime: Math.floor(process.uptime()), nodeVersion: process.version, platform: process.platform, deployedAt: new Date().toISOString(), }); }); app.post('/api/echo', (req, res) => { const { text } = req.body; if (!text) return res.status(400).json({ error: '텍스트를 입력해주세요.' }); res.json({ echo: text, length: text.length }); }); // Fallback to index.html for unknown routes app.get('*', (req, res) => { res.sendFile(path.join(__dirname, 'public', 'index.html')); }); app.listen(PORT, () => { console.log(`서버 실행 중: http://localhost:${PORT}`); });