From 1fb9a33776817822743e1b218cad696869dad4b9 Mon Sep 17 00:00:00 2001 From: choibk Date: Fri, 23 Jan 2026 20:58:22 +0900 Subject: [PATCH] Chore: Prepare for Synology NAS deployment (Serve static client, dynamic API_BASE) --- client/src/App.tsx | 4 +++- server/server.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 0212d45..c38c974 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -2,7 +2,9 @@ import { useState, useEffect, useMemo } from 'react'; import axios from 'axios'; import { Key, Plus, Copy, CheckCircle, Clock, Search, Users, ChevronRight, ArrowLeft, Trash2 } from 'lucide-react'; -const API_BASE = 'http://localhost:3006/api'; +const API_BASE = import.meta.env.DEV + ? 'http://localhost:3006/api' + : '/api'; interface License { id: number; diff --git a/server/server.js b/server/server.js index 60da100..9345178 100644 --- a/server/server.js +++ b/server/server.js @@ -109,6 +109,22 @@ app.post('/api/licenses/generate', async (req, res) => { } }); +// Serve Static Files (Production) +const clientDistPath = path.join(__dirname, '../client/dist'); +if (fs.existsSync(clientDistPath)) { + app.use(express.static(clientDistPath)); + + // SPA Fallback: Any route not handled by API should return index.html + app.get('*', (req, res) => { + if (!req.path.startsWith('/api')) { + res.sendFile(path.join(clientDistPath, 'index.html')); + } + }); + console.log(`📁 Serving client from ${clientDistPath}`); +} else { + console.log('⚠️ Client dist folder not found. API mode only.'); +} + app.listen(PORT, () => { console.log(`🚀 License Manager Server running on port ${PORT}`); });