1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 22:13:53 +01:00

Add fixes for proxy

This commit is contained in:
Konrad Kosmatka
2024-02-05 13:30:33 +01:00
parent f5a31e90aa
commit 46c6a1cf66
7 changed files with 26 additions and 31 deletions

View File

@@ -334,7 +334,7 @@ app.get('/getDevices', (req, res) => {
*/ */
wss.on('connection', (ws, request) => { wss.on('connection', (ws, request) => {
const clientIp = request.connection.remoteAddress; const clientIp = request.headers['x-forwarded-for'] || request.connection.remoteAddress;
currentUsers++; currentUsers++;
dataHandler.showOnlineUsers(currentUsers); dataHandler.showOnlineUsers(currentUsers);
@@ -409,4 +409,4 @@ httpServer.listen(serverConfig.webserver.webserverPort, serverConfig.webserver.w
module.exports = { module.exports = {
serverConfig serverConfig
} }

View File

@@ -11,7 +11,7 @@
<meta property="og:title" content="FM-DX WebServer"> <meta property="og:title" content="FM-DX WebServer">
<meta property="og:type" content="website"> <meta property="og:type" content="website">
<meta property="og:image" content="/favicon2.png"> <meta property="og:image" content="favicon2.png">
<meta property="og:description" content="This server us running the FM-DX Webserver software by Noobish."> <meta property="og:description" content="This server us running the FM-DX Webserver software by Noobish.">
<!-- 3LAS Scripts for Audio streaming --> <!-- 3LAS Scripts for Audio streaming -->
@@ -230,11 +230,11 @@
</div> </div>
<% if (isAdminAuthenticated) { %> <% if (isAdminAuthenticated) { %>
<p>You are logged in as an adminstrator. <a href="/setup">Setup</a> | <a class="logout-link" href="#">Logout</a></p> <p>You are logged in as an adminstrator. <a href="./setup">Setup</a> | <a class="logout-link" href="#">Logout</a></p>
<% } else if (isTuneAuthenticated) { %> <% } else if (isTuneAuthenticated) { %>
<p>You are logged in and can control the receiver. <a class="logout-link" href="#">Logout</a></p> <p>You are logged in and can control the receiver. <a class="logout-link" href="#">Logout</a></p>
<% } else { %> <% } else { %>
<form action="/login" method="post" id="login-form"> <form action="./login" method="post" id="login-form">
<label for="password">Password:</label> <label for="password">Password:</label>
<input type="password" id="password" name="password" required> <input type="password" id="password" name="password" required>
<button type="submit" class="br-0 w-100" style="height: 44px">Login</button> <button type="submit" class="br-0 w-100" style="height: 44px">Login</button>
@@ -258,4 +258,4 @@
</div> </div>
<script src="js/webserver.js"></script> <script src="js/webserver.js"></script>
</body> </body>
</html> </html>

View File

@@ -1,7 +1,6 @@
var hostParts = window.location.host.split(':'); var url = new URL('text', window.location.href);
var hostname = hostParts[0]; // Extract the hostname url.protocol = url.protocol.replace('http', 'ws');
var port = hostParts[1] || '8080'; // Extract the port or use a default (e.g., 8080) var socketAddress = url.href;
var socketAddress = 'ws://' + hostname + ':' + port + '/text'; // Use 'wss' for secure WebSocket connections (recommended for external access)
var socket = new WebSocket(socketAddress); var socket = new WebSocket(socketAddress);
var parsedData; var parsedData;
var data = []; var data = [];
@@ -121,7 +120,7 @@ $(document).ready(function() {
function getInitialSettings() { function getInitialSettings() {
$.ajax({ $.ajax({
url: '/static_data', url: './static_data',
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
// Use the received data (data.qthLatitude, data.qthLongitude) as needed // Use the received data (data.qthLatitude, data.qthLongitude) as needed
@@ -521,4 +520,4 @@ function toggleButtonState(buttonId) {
message += parsedData.eq ? "1" : "0"; message += parsedData.eq ? "1" : "0";
message += parsedData.ims ? "1" : "0"; message += parsedData.ims ? "1" : "0";
socket.send(message); socket.send(message);
} }

View File

@@ -54,7 +54,7 @@
// Perform an AJAX request to the /login endpoint // Perform an AJAX request to the /login endpoint
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/login', url: './login',
data: $(this).serialize(), data: $(this).serialize(),
success: function (data) { success: function (data) {
// Update the content on the page with the message from the response // Update the content on the page with the message from the response
@@ -83,7 +83,7 @@
// Perform an AJAX request to the /logout endpoint // Perform an AJAX request to the /logout endpoint
$.ajax({ $.ajax({
type: 'GET', // Assuming the logout is a GET request, adjust accordingly type: 'GET', // Assuming the logout is a GET request, adjust accordingly
url: '/logout', url: './logout',
success: function (data) { success: function (data) {
// Update the content on the page with the message from the response // Update the content on the page with the message from the response
$('#login-message').text(data.message); $('#login-message').text(data.message);
@@ -113,4 +113,4 @@
$(':root').css('--color-main', themeColors[0]); $(':root').css('--color-main', themeColors[0]);
$(':root').css('--color-main-bright', themeColors[1]); $(':root').css('--color-main-bright', themeColors[1]);
} }
} }

View File

@@ -2,10 +2,6 @@ var map;
var pin; var pin;
var tilesURL='https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}.png'; var tilesURL='https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}.png';
var mapAttrib='&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, Tiles by <a href="http://stadiamaps.com/" target="_blank">Stadiamaps</a>'; var mapAttrib='&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, Tiles by <a href="http://stadiamaps.com/" target="_blank">Stadiamaps</a>';
var hostParts = window.location.host.split(':');
var hostname = hostParts[0]; // Extract the hostname
var port = hostParts[1] || '80'; // Extract the port or use a default (e.g., 8080)
var serverAddress = 'http://' + hostname + ':' + port;
// add map container // add map container
@@ -36,7 +32,7 @@ $(document).ready(function() {
// Perform an AJAX request to the /login endpoint // Perform an AJAX request to the /login endpoint
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/login', url: './login',
data: $(this).serialize(), data: $(this).serialize(),
success: function (data) { success: function (data) {
// Update the content on the page with the message from the response // Update the content on the page with the message from the response
@@ -65,7 +61,7 @@ $(document).ready(function() {
// Perform an AJAX request to the /logout endpoint // Perform an AJAX request to the /logout endpoint
$.ajax({ $.ajax({
type: 'GET', // Assuming the logout is a GET request, adjust accordingly type: 'GET', // Assuming the logout is a GET request, adjust accordingly
url: '/logout', url: './logout',
success: function (data) { success: function (data) {
// Update the content on the page with the message from the response // Update the content on the page with the message from the response
$('#login-message').text(data.message); $('#login-message').text(data.message);
@@ -108,7 +104,7 @@ function MapCreate() {
function fetchData() { function fetchData() {
// Make a GET request to retrieve the data.json file // Make a GET request to retrieve the data.json file
fetch(serverAddress + "/getData") fetch("./getData")
.then(response => { .then(response => {
if (!response.ok) { if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`); throw new Error(`HTTP error! Status: ${response.status}`);
@@ -231,7 +227,7 @@ function submitData() {
} }
// Send data to the server using jQuery // Send data to the server using jQuery
$.ajax({ $.ajax({
url: serverAddress + '/saveData', url: './saveData',
type: 'POST', type: 'POST',
contentType: 'application/json', contentType: 'application/json',
data: JSON.stringify(data), data: JSON.stringify(data),
@@ -242,4 +238,4 @@ function submitData() {
console.error(error); console.error(error);
} }
}); });
} }

View File

@@ -1,4 +1,4 @@
$.getScript('/js/main.js'); $.getScript('./js/main.js');
$.getScript('/js/dropdown.js'); $.getScript('./js/dropdown.js');
$.getScript('/js/modal.js'); $.getScript('./js/modal.js');
$.getScript('/js/settings.js'); $.getScript('./js/settings.js');

View File

@@ -150,7 +150,7 @@
<div class="panel-100 no-bg"> <div class="panel-100 no-bg">
<p>Feel free to contact us on <a href="https://discord.gg/ZAVNdS74mC" target="_blank"><strong><i class="fa-brands fa-discord"></i> Discord</strong></a> for community support.</p> <p>Feel free to contact us on <a href="https://discord.gg/ZAVNdS74mC" target="_blank"><strong><i class="fa-brands fa-discord"></i> Discord</strong></a> for community support.</p>
</div> </div>
<button onclick="document.location.href='/'" id="back-btn" aria-label="Go back to tuning"><i class="fa-solid fa-arrow-left"></i></button> <button onclick="document.location.href='./'" id="back-btn" aria-label="Go back to tuning"><i class="fa-solid fa-arrow-left"></i></button>
<% } else { %> <% } else { %>
<div class="panel-100 no-bg"> <div class="panel-100 no-bg">
<h1>FM-DX WebServer</h1> <h1>FM-DX WebServer</h1>
@@ -160,7 +160,7 @@
</div> </div>
<div class="panel-100 p-bottom-20"> <div class="panel-100 p-bottom-20">
<h2>LOGIN</h2> <h2>LOGIN</h2>
<form action="/login" method="post" id="login-form"> <form action="./login" method="post" id="login-form">
<input style="background-color: var(--color-2);" type="password" id="password" name="password" required> <input style="background-color: var(--color-2);" type="password" id="password" name="password" required>
<button type="submit" class="br-0 w-100" style="height: 44px;">Login</button> <button type="submit" class="br-0 w-100" style="height: 44px;">Login</button>
</form> </form>
@@ -172,4 +172,4 @@
<script src="js/dropdown.js"></script> <script src="js/dropdown.js"></script>
<script src="js/setup.js"></script> <script src="js/setup.js"></script>
</body> </body>
</html> </html>