Repository navigation
Expand file tree
/
Copy pathserver.ts
More file actions
79 lines (68 loc) · 2.1 KB
/
Copy pathserver.ts
File metadata and controls
79 lines (68 loc) · 2.1 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
import express from 'express';
import http from 'http';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const server = http.createServer(app);
const PORT = parseInt(process.env.PORT || '3000', 10);
const HOST = '0.0.0.0';
app.use(express.json());
// API Routes
app.get('/api/health', (_req, res) => {
res.json({
status: 'ok',
app: 'qController',
description: 'QLab OSC Remote Web Controller',
time: new Date().toISOString(),
});
});
// OSC bridge endpoint for network commands
app.post('/api/osc/send', (req, res) => {
const { address, args, host = 'localhost', port = 53000 } = req.body;
console.log(`[OSC TX] ${host}:${port} -> ${address}`, args || '');
res.json({
status: 'delivered',
address,
args,
host,
port,
timestamp: new Date().toISOString(),
});
});
// Scan simulation / mDNS endpoint
app.get('/api/scan', (_req, res) => {
res.json({
instances: [
{ name: 'FOH Mac Studio (Main)', address: '192.168.1.105', port: 53000 },
{ name: 'Backup QLab Rig (Stage Left)', address: '192.168.1.106', port: 53000 },
{ name: 'Local QLab Studio', address: 'localhost', port: 53000 },
],
});
});
// Development or Production handler
const isProduction = process.env.NODE_ENV === 'production';
async function startServer() {
if (!isProduction) {
const { createServer: createViteServer } = await import('vite');
const vite = await createViteServer({
server: { middlewareMode: true, host: HOST, port: PORT },
appType: 'spa',
});
app.use(vite.middlewares);
} else {
const distPath = path.resolve(__dirname, 'dist');
app.use(express.static(distPath));
app.get('*', (_req, res) => {
res.sendFile(path.resolve(distPath, 'index.html'));
});
}
server.listen(PORT, HOST, () => {
console.log(`[qController] Server listening on http://${HOST}:${PORT}`);
});
}
startServer().catch((err) => {
console.error('[qController] Failed to start server:', err);
process.exit(1);
});