Fix dynamic API base path for server deployment

This commit is contained in:
pongpon pitisuk
2026-09-12 14:34:09 +07:00
parent 72eb7cd0c8
commit e01d01464a
9 changed files with 262 additions and 52 deletions
+6 -2
View File
@@ -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'; },