fix: support authenticated web deployments under a reverse proxy path

This commit is contained in:
AttilaNet
2026-11-10 20:01:44 +08:00
parent 0230a933b0
commit 99aff423d8
12 changed files with 529 additions and 31 deletions
+7 -2
View File
@@ -1,4 +1,8 @@
const form = document.querySelector('#auth-form');
// Keep login standalone: the server renders the prefix in both HTML documents.
const basePath = (document.querySelector('meta[name="ranch-web-base-path"]')?.content || '').replace(/\/+$/, '');
const webPath = path => `${basePath}${path}`;
form.setAttribute('action', webPath('/api/auth/login'));
const input = document.querySelector('#admin-password');
const button = form.querySelector('button[type="submit"]');
const status = document.querySelector('#auth-status');
@@ -24,16 +28,17 @@ function openWorkbench() {
leaving = true;
input.value = '';
setBusy(true, '正在进入工作台…');
location.replace('/');
location.replace(webPath('/'));
}
async function authRequest(path, body) {
let response;
try {
response = await fetch(path, {
response = await fetch(webPath(path), {
method: body === undefined ? 'GET' : 'POST',
credentials: 'same-origin',
cache: 'no-store',
redirect: 'error',
headers: body === undefined ? {Accept: 'application/json'} : {Accept: 'application/json', 'Content-Type': 'application/json'},
body,
});