fix: use native fetch with credentials for remote dashboard
This commit is contained in:
parent
11987a8311
commit
18628e9e36
|
|
@ -5,7 +5,28 @@
|
|||
const { React } = SDK;
|
||||
const { useState, useEffect, useCallback } = SDK.hooks;
|
||||
const { Card, CardHeader, CardTitle, CardContent, Button } = SDK.components;
|
||||
const fetchJSON = SDK.fetchJSON;
|
||||
|
||||
// Use native fetch with credentials for remote dashboard
|
||||
async function apiFetch(path) {
|
||||
const res = await fetch(path, { credentials: "include" });
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error("API error " + res.status + ": " + text.slice(0, 100));
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function apiPost(path) {
|
||||
const res = await fetch(path, {
|
||||
method: "POST",
|
||||
credentials: "include"
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error("API error " + res.status + ": " + text.slice(0, 100));
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
function SSHXPage() {
|
||||
const [link, setLink] = useState(null);
|
||||
|
|
@ -16,7 +37,7 @@
|
|||
setStatus("loading");
|
||||
setError(null);
|
||||
try {
|
||||
const res = await fetchJSON("/api/plugins/sshx-link/start");
|
||||
const res = await apiFetch("/api/plugins/sshx-link/start");
|
||||
if (res.link) {
|
||||
setLink(res.link);
|
||||
setStatus("running");
|
||||
|
|
@ -32,7 +53,7 @@
|
|||
|
||||
const stopSSHX = useCallback(async function () {
|
||||
try {
|
||||
await fetchJSON("/api/plugins/sshx-link/stop");
|
||||
await apiPost("/api/plugins/sshx-link/stop");
|
||||
setLink(null);
|
||||
setStatus("idle");
|
||||
} catch (err) {
|
||||
|
|
@ -42,7 +63,7 @@
|
|||
|
||||
const checkStatus = useCallback(async function () {
|
||||
try {
|
||||
const res = await fetchJSON("/api/plugins/sshx-link/status");
|
||||
const res = await apiFetch("/api/plugins/sshx-link/status");
|
||||
if (res.status === "running" && res.link) {
|
||||
setLink(res.link);
|
||||
setStatus("running");
|
||||
|
|
|
|||
Loading…
Reference in New Issue