diff --git a/server/routers/questioneer/public/admin.html b/server/routers/questioneer/public/admin.html index e692827..57aa8de 100644 --- a/server/routers/questioneer/public/admin.html +++ b/server/routers/questioneer/public/admin.html @@ -13,7 +13,9 @@ return '/ms/questioneer/static'; } else { // Для локальной разработки - return window.location.pathname.split('/admin')[0] + '/static'; + const basePath = window.location.pathname.split('/admin')[0]; + // Проверяем, заканчивается ли путь на слеш + return basePath + (basePath.endsWith('/') ? 'static' : '/static'); } } diff --git a/server/routers/questioneer/public/create.html b/server/routers/questioneer/public/create.html index ea975c9..51942ab 100644 --- a/server/routers/questioneer/public/create.html +++ b/server/routers/questioneer/public/create.html @@ -13,7 +13,9 @@ return '/ms/questioneer/static'; } else { // Для локальной разработки - return window.location.pathname.split('/create')[0] + '/static'; + const basePath = window.location.pathname.split('/create')[0]; + // Проверяем, заканчивается ли путь на слеш + return basePath + (basePath.endsWith('/') ? 'static' : '/static'); } } diff --git a/server/routers/questioneer/public/edit.html b/server/routers/questioneer/public/edit.html index 0f9c007..77b92b3 100644 --- a/server/routers/questioneer/public/edit.html +++ b/server/routers/questioneer/public/edit.html @@ -13,7 +13,9 @@ return '/ms/questioneer/static'; } else { // Для локальной разработки - return window.location.pathname.split('/edit')[0] + '/static'; + const basePath = window.location.pathname.split('/edit')[0]; + // Проверяем, заканчивается ли путь на слеш + return basePath + (basePath.endsWith('/') ? 'static' : '/static'); } } diff --git a/server/routers/questioneer/public/index.html b/server/routers/questioneer/public/index.html index 94feea7..481e578 100644 --- a/server/routers/questioneer/public/index.html +++ b/server/routers/questioneer/public/index.html @@ -16,7 +16,7 @@ // Для локальной разработки // Если путь заканчивается на слеш или на /questioneer, добавляем /static if (pathname.endsWith('/') || pathname.endsWith('/questioneer')) { - return pathname + 'static'; + return pathname + '/static'; } else { return pathname + '/static'; } diff --git a/server/routers/questioneer/public/poll.html b/server/routers/questioneer/public/poll.html index 44e70cc..8d9807a 100644 --- a/server/routers/questioneer/public/poll.html +++ b/server/routers/questioneer/public/poll.html @@ -13,7 +13,9 @@ return '/ms/questioneer/static'; } else { // Для локальной разработки - return window.location.pathname.split('/poll')[0] + '/static'; + const basePath = window.location.pathname.split('/poll')[0]; + // Проверяем, заканчивается ли путь на слеш + return basePath + (basePath.endsWith('/') ? 'static' : '/static'); } } diff --git a/server/routers/questioneer/public/static/js/admin.js b/server/routers/questioneer/public/static/js/admin.js index 14f5f0a..7d09522 100644 --- a/server/routers/questioneer/public/static/js/admin.js +++ b/server/routers/questioneer/public/static/js/admin.js @@ -13,16 +13,12 @@ $(document).ready(function() { // Для продакшна: если в пути есть /ms/, то API доступно по /ms/questioneer/api return '/ms/questioneer/api'; } else { - // Для локальной разработки: используем обычный путь - // Извлекаем базовый путь из URL страницы - const pathParts = pathname.split('/'); - // Если последний сегмент пустой (из-за /) - удаляем его - if (pathParts[pathParts.length - 1] === '') { - pathParts.pop(); - } + // Для локальной разработки: формируем путь к API без учета текущей страницы + // Извлекаем базовый путь из URL страницы до /admin/[adminLink] + const basePath = pathname.split('/admin')[0]; - // Путь до корня приложения - return pathParts.join('/') + '/api'; + // Путь до API приложения + return basePath + '/api'; } }; diff --git a/server/routers/questioneer/public/static/js/create.js b/server/routers/questioneer/public/static/js/create.js index 3b19c3b..e979449 100644 --- a/server/routers/questioneer/public/static/js/create.js +++ b/server/routers/questioneer/public/static/js/create.js @@ -16,16 +16,12 @@ $(document).ready(function() { // Для продакшна: если в пути есть /ms/, то API доступно по /ms/questioneer/api return '/ms/questioneer/api'; } else { - // Для локальной разработки: используем обычный путь - // Извлекаем базовый путь из URL страницы - const pathParts = pathname.split('/'); - // Если последний сегмент пустой (из-за /) - удаляем его - if (pathParts[pathParts.length - 1] === '') { - pathParts.pop(); - } + // Для локальной разработки: формируем путь к API без учета текущей страницы + // Извлекаем базовый путь из URL страницы до /create + const basePath = pathname.split('/create')[0]; - // Путь до корня приложения - return pathParts.join('/') + '/api'; + // Путь до API приложения + return basePath + '/api'; } }; diff --git a/server/routers/questioneer/public/static/js/edit.js b/server/routers/questioneer/public/static/js/edit.js index 7f41098..15e35a8 100644 --- a/server/routers/questioneer/public/static/js/edit.js +++ b/server/routers/questioneer/public/static/js/edit.js @@ -18,16 +18,15 @@ $(document).ready(function() { // Для продакшна: если в пути есть /ms/, то API доступно по /ms/questioneer/api return '/ms/questioneer/api'; } else { - // Для локальной разработки: используем обычный путь - // Извлекаем базовый путь из URL страницы - const pathParts = pathname.split('/'); - // Если последний сегмент пустой (из-за /) - удаляем его - if (pathParts[pathParts.length - 1] === '') { - pathParts.pop(); - } + // Для локальной разработки: формируем путь к API без учета текущей страницы + // Извлекаем базовый путь из URL страницы до /edit/[adminLink] + const basePath = pathname.split('/edit')[0]; - // Путь до корня приложения - return pathParts.join('/') + '/api'; + // Убеждаемся, что путь не заканчивается на /admin, если это часть URL + const cleanPath = basePath.endsWith('/admin') ? basePath.slice(0, -6) : basePath; + + // Путь до API приложения + return cleanPath + '/api'; } }; diff --git a/server/routers/questioneer/public/static/js/index.js b/server/routers/questioneer/public/static/js/index.js index 243fe0a..e616047 100644 --- a/server/routers/questioneer/public/static/js/index.js +++ b/server/routers/questioneer/public/static/js/index.js @@ -10,16 +10,12 @@ $(document).ready(function() { // Для продакшна: если в пути есть /ms/, то API доступно по /ms/questioneer/api return '/ms/questioneer/api'; } else { - // Для локальной разработки: используем обычный путь - // Извлекаем базовый путь из URL страницы - const pathParts = pathname.split('/'); - // Если последний сегмент пустой (из-за /) - удаляем его - if (pathParts[pathParts.length - 1] === '') { - pathParts.pop(); - } + // Для локальной разработки: формируем путь к API для главной страницы + // Убираем завершающий слеш, если он есть + const basePath = pathname.endsWith('/') ? pathname.slice(0, -1) : pathname; - // Путь до корня приложения - return pathParts.join('/') + '/api'; + // Путь до API приложения + return basePath + '/api'; } }; diff --git a/server/routers/questioneer/public/static/js/poll.js b/server/routers/questioneer/public/static/js/poll.js index 8f64a65..adbdd4d 100644 --- a/server/routers/questioneer/public/static/js/poll.js +++ b/server/routers/questioneer/public/static/js/poll.js @@ -63,22 +63,12 @@ $(document).ready(function() { // Для продакшна: если в пути есть /ms/, то API доступно по /ms/questioneer/api return '/ms/questioneer/api'; } else { - // Для локальной разработки: используем обычный путь - // Извлекаем базовый путь из URL страницы - const pathParts = pathname.split('/'); - // Убираем slug и последний сегмент (poll/[id]) - if (pathParts.length > 2) { - // Удаляем 2 последних сегмента пути (poll/[id]) - pathParts.pop(); - pathParts.pop(); - } - // Если последний сегмент пустой (из-за /) - удаляем его - if (pathParts[pathParts.length - 1] === '') { - pathParts.pop(); - } + // Для локальной разработки: формируем путь к API без учета текущей страницы + // Извлекаем базовый путь из URL страницы до /poll + const basePath = pathname.split('/poll')[0]; - // Путь до корня приложения - return pathParts.join('/') + '/api'; + // Путь до API приложения + return basePath + '/api'; } };