Fix dynamic API base path for server deployment
This commit is contained in:
@@ -3,8 +3,12 @@
|
||||
* API communication, Auth state, Toast notifications, Theme
|
||||
*/
|
||||
|
||||
const getAppBasePath = () => {
|
||||
return window.location.pathname.includes('/survey') ? '/survey' : '';
|
||||
};
|
||||
|
||||
const API = {
|
||||
base: '/survey/api',
|
||||
base: `${getAppBasePath()}/api`,
|
||||
|
||||
async request(endpoint, options = {}) {
|
||||
const url = `${this.base}/${endpoint}`;
|
||||
@@ -66,7 +70,7 @@ const Auth = {
|
||||
async logout() {
|
||||
await API.post('auth.php?action=logout', {});
|
||||
this.user = null;
|
||||
window.location.href = '/survey/index.html';
|
||||
window.location.href = `${getAppBasePath()}/index.html`;
|
||||
},
|
||||
|
||||
isAdmin() { return this.user?.role === 'admin'; },
|
||||
|
||||
Reference in New Issue
Block a user