Update server.ts
Browse files
server.ts
CHANGED
|
@@ -4,6 +4,10 @@ import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
| 4 |
import path from 'path';
|
| 5 |
import crypto from 'crypto';
|
| 6 |
import { createRequire } from 'module';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
const require = createRequire(import.meta.url);
|
| 9 |
const NodeMediaServer = require('node-media-server');
|
|
@@ -12,6 +16,12 @@ async function startServer() {
|
|
| 12 |
const app = express();
|
| 13 |
const PORT = process.env.PORT ? parseInt(process.env.PORT as string, 10) : 3000;
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
// Start Node Media Server for RTMP Ingest (1935) and HTTP FLV (8123)
|
| 16 |
const nmsConfig = {
|
| 17 |
rtmp: {
|
|
@@ -68,8 +78,15 @@ async function startServer() {
|
|
| 68 |
app.use(vite.middlewares);
|
| 69 |
} else {
|
| 70 |
// production mode
|
| 71 |
-
|
|
|
|
| 72 |
app.use(express.static(distPath));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
app.get('*', (req, res) => {
|
| 74 |
res.sendFile(path.join(distPath, 'index.html'));
|
| 75 |
});
|
|
|
|
| 4 |
import path from 'path';
|
| 5 |
import crypto from 'crypto';
|
| 6 |
import { createRequire } from 'module';
|
| 7 |
+
import { fileURLToPath } from 'url';
|
| 8 |
+
|
| 9 |
+
const __filename = fileURLToPath(import.meta.url);
|
| 10 |
+
const __dirname = path.dirname(__filename);
|
| 11 |
|
| 12 |
const require = createRequire(import.meta.url);
|
| 13 |
const NodeMediaServer = require('node-media-server');
|
|
|
|
| 16 |
const app = express();
|
| 17 |
const PORT = process.env.PORT ? parseInt(process.env.PORT as string, 10) : 3000;
|
| 18 |
|
| 19 |
+
// Logging middleware
|
| 20 |
+
app.use((req, res, next) => {
|
| 21 |
+
console.log(`[REQ] ${req.method} ${req.url}`);
|
| 22 |
+
next();
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
// Start Node Media Server for RTMP Ingest (1935) and HTTP FLV (8123)
|
| 26 |
const nmsConfig = {
|
| 27 |
rtmp: {
|
|
|
|
| 78 |
app.use(vite.middlewares);
|
| 79 |
} else {
|
| 80 |
// production mode
|
| 81 |
+
// __dirname is the directory where server.js is located (which should be 'dist' thanks to esbuild)
|
| 82 |
+
const distPath = __dirname;
|
| 83 |
app.use(express.static(distPath));
|
| 84 |
+
|
| 85 |
+
// Add health diagnostic endpoint
|
| 86 |
+
app.get('/api/health', (req, res) => {
|
| 87 |
+
res.json({ status: 'ok', dir: __dirname, time: new Date().toISOString() });
|
| 88 |
+
});
|
| 89 |
+
|
| 90 |
app.get('*', (req, res) => {
|
| 91 |
res.sendFile(path.join(distPath, 'index.html'));
|
| 92 |
});
|