You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-27 14:33:52 +01:00
Add proxying for /audio to localhost:8081
This commit is contained in:
29
index.js
29
index.js
@@ -7,6 +7,7 @@ const express = require('express');
|
|||||||
const session = require('express-session');
|
const session = require('express-session');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
const httpProxy = require('http-proxy');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const app = express();
|
const app = express();
|
||||||
const httpServer = http.createServer(app);
|
const httpServer = http.createServer(app);
|
||||||
@@ -18,6 +19,13 @@ const path = require('path');
|
|||||||
const net = require('net');
|
const net = require('net');
|
||||||
const client = new net.Socket();
|
const client = new net.Socket();
|
||||||
|
|
||||||
|
// Create a WebSocket proxy instance
|
||||||
|
const proxy = httpProxy.createProxyServer({
|
||||||
|
target: 'ws://localhost:8081', // WebSocket httpServer's address
|
||||||
|
ws: true, // Enable WebSocket proxying
|
||||||
|
changeOrigin: true // Change the origin of the host header to the target URL
|
||||||
|
});
|
||||||
|
|
||||||
// Other files and libraries
|
// Other files and libraries
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@@ -428,14 +436,23 @@ wss.on('connection', (ws, request) => {
|
|||||||
ws.on('error', console.error);
|
ws.on('error', console.error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle upgrade requests to proxy WebSocket connections
|
||||||
httpServer.on('upgrade', (request, socket, head) => {
|
httpServer.on('upgrade', (request, socket, head) => {
|
||||||
sessionMiddleware(request, {}, () => {
|
|
||||||
wss.handleUpgrade(request, socket, head, (ws) => {
|
logInfo(request.url);
|
||||||
wss.emit('connection', ws, request);
|
if (request.url === '/text') {
|
||||||
|
sessionMiddleware(request, {}, () => {
|
||||||
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
||||||
|
wss.emit('connection', ws, request);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} else if (request.url === '/audio/') {
|
||||||
});
|
proxy.ws(request, socket, head);
|
||||||
|
} else {
|
||||||
|
socket.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/* Serving of HTML files */
|
/* Serving of HTML files */
|
||||||
app.use(express.static(path.join(__dirname, 'web')));
|
app.use(express.static(path.join(__dirname, 'web')));
|
||||||
|
|||||||
Reference in New Issue
Block a user