fix путей

This commit is contained in:
Primakov Alexandr Alexandrovich
2025-03-12 00:09:36 +03:00
parent 1fcc5ed70d
commit dd589790c2
12 changed files with 1997 additions and 529 deletions

View File

@@ -8,13 +8,27 @@ $(document).ready(function() {
let questionCount = 0;
let questionnaireData = null;
// Получаем базовый путь API
// Функция для получения базового пути API
const getApiPath = () => {
const pathParts = window.location.pathname.split('/');
// Убираем последние две части пути (edit/:adminLink)
pathParts.pop();
pathParts.pop();
return pathParts.join('/') + '/api';
// Проверяем, содержит ли путь /ms/ (продакшн на dev.bro-js.ru)
const pathname = window.location.pathname;
const isMsPath = pathname.includes('/ms/questioneer');
if (isMsPath) {
// Для продакшна: если в пути есть /ms/, то API доступно по /ms/questioneer/api
return '/ms/questioneer/api';
} else {
// Для локальной разработки: используем обычный путь
// Извлекаем базовый путь из URL страницы
const pathParts = pathname.split('/');
// Если последний сегмент пустой (из-за /) - удаляем его
if (pathParts[pathParts.length - 1] === '') {
pathParts.pop();
}
// Путь до корня приложения
return pathParts.join('/') + '/api';
}
};
// Загрузка данных опроса
@@ -312,10 +326,20 @@ $(document).ready(function() {
data: JSON.stringify(questionnaire),
success: function(result) {
if (result.success) {
showAlert('Опрос успешно обновлен', 'Успешно', function() {
const basePath = window.location.pathname.split('/edit')[0];
window.location.href = `${basePath}/admin/${adminLink}`;
});
showAlert('Опрос успешно сохранен!', 'Успех', { autoClose: true });
// Перенаправляем на страницу администратора
const isMsPath = window.location.pathname.includes('/ms/questioneer');
let basePath;
if (isMsPath) {
// Для продакшна: используем /ms/questioneer
basePath = '/ms/questioneer';
} else {
// Для локальной разработки: используем текущий путь
basePath = window.location.pathname.split('/edit')[0];
}
window.location.href = `${basePath}/admin/${adminLink}`;
} else {
showAlert(`Ошибка при обновлении опроса: ${result.error}`, 'Ошибка');
}