Refactor app to React Router and Tailwind

This commit is contained in:
TopherMayor
2026-06-12 10:35:19 -07:00
parent 11f5d1b225
commit fa0a7f44b7
15 changed files with 3157 additions and 318 deletions

View File

@@ -12,6 +12,9 @@ const app = express();
const server = http.createServer(app);
const wss = new WebSocketServer({ server });
const PUBLIC_DIR = path.join(__dirname, 'public');
const CLIENT_DIST_DIR = path.join(__dirname, 'client', 'dist');
const CLIENT_INDEX_FILE = path.join(CLIENT_DIST_DIR, 'index.html');
const DEFAULT_DATA_DIR = path.join(__dirname, 'data');
const DATA_DIR = process.env.DATA_DIR
? path.resolve(process.env.DATA_DIR)
@@ -30,10 +33,13 @@ app.use(cors());
app.use(express.json());
app.get('/admin', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'admin.html'));
res.sendFile(path.join(PUBLIC_DIR, 'admin.html'));
});
app.use(express.static(path.join(__dirname, 'public')));
if (fs.existsSync(CLIENT_INDEX_FILE)) {
app.use(express.static(CLIENT_DIST_DIR));
}
app.use(express.static(PUBLIC_DIR));
function loadData() {
if (!fs.existsSync(DATA_DIR)) fs.mkdirSync(DATA_DIR, { recursive: true });
@@ -1021,6 +1027,16 @@ app.get('/api/yelp', async (req, res) => {
}
});
app.get('*', (req, res, next) => {
if (req.path.startsWith('/api/') || req.path === '/admin') {
return next();
}
if (!fs.existsSync(CLIENT_INDEX_FILE)) {
return next();
}
return res.sendFile(CLIENT_INDEX_FILE);
});
wss.on('connection', (ws) => {
ws.send(JSON.stringify(buildRealtimeSnapshot()));