fix: support authenticated web deployments under a reverse proxy path
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user