fix: use serverId variable and add Accept: application/json to server-show.js fetch calls

This commit is contained in:
2026-06-14 09:02:13 -04:00
parent d1da560764
commit 4ce6b27f96

View File

@@ -152,9 +152,10 @@ function confirmAgentAction() {
closeAgentModal(); closeAgentModal();
fetch('/servers/serverId/agent/' + action, { fetch('/servers/' + serverId + '/agent/' + action, {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken(), 'X-CSRF-Token': getCsrfToken(),
}, },
@@ -192,9 +193,10 @@ function copyAgentKey() {
function regenerateAgentKey() { function regenerateAgentKey() {
if (!confirm('Regenerate agent key? The current key will stop working immediately.')) return; if (!confirm('Regenerate agent key? The current key will stop working immediately.')) return;
fetch('/servers/serverId/agent/regenerate-key', { fetch('/servers/' + serverId + '/agent/regenerate-key', {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken(), 'X-CSRF-Token': getCsrfToken(),
}, },
@@ -221,9 +223,10 @@ function serverAction(action) {
if (!confirm('Are you sure you want to ' + action + ' this server?')) return; if (!confirm('Are you sure you want to ' + action + ' this server?')) return;
} }
fetch('/servers/serverId/' + action, { fetch('/servers/' + serverId + '/' + action, {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken(), 'X-CSRF-Token': getCsrfToken(),
}, },
@@ -240,9 +243,10 @@ function restartService() {
const service = prompt('Enter service name to restart (e.g., nginx, mysql, apache2):'); const service = prompt('Enter service name to restart (e.g., nginx, mysql, apache2):');
if (!service) return; if (!service) return;
fetch('/servers/serverId/restart-service', { fetch('/servers/' + serverId + '/restart-service', {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken(), 'X-CSRF-Token': getCsrfToken(),
}, },
@@ -256,7 +260,9 @@ function restartService() {
} }
function refreshMetrics() { function refreshMetrics() {
fetch('/servers/serverId/metrics') fetch('/servers/' + serverId + '/metrics', {
headers: { 'Accept': 'application/json' },
})
.then(r => r.json()) .then(r => r.json())
.then(data => { .then(data => {
if (data.success && data.data) { if (data.success && data.data) {
@@ -303,9 +309,10 @@ function saveThresholds() {
document.querySelector('#thresholdModal .btn-primary').disabled = true; document.querySelector('#thresholdModal .btn-primary').disabled = true;
fetch('/servers/serverId/thresholds', { fetch('/servers/' + serverId + '/thresholds', {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-Token': getCsrfToken(), 'X-CSRF-Token': getCsrfToken(),
}, },