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

@@ -6,12 +6,27 @@ $(document).ready(function() {
let questionCount = 0;
// Получаем базовый путь API (для работы и с /questioneer, и с /ms/questioneer)
// Функция для получения базового пути API
const getApiPath = () => {
const pathParts = window.location.pathname.split('/');
// Убираем последнюю часть пути (create)
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';
}
};
// Добавление нового вопроса
@@ -217,8 +232,18 @@ $(document).ready(function() {
data: JSON.stringify(questionnaire),
success: function(result) {
if (result.success) {
// Перенаправление на страницу администрирования опроса
const basePath = window.location.pathname.split('/create')[0];
// Перенаправляем на страницу администратора
const isMsPath = window.location.pathname.includes('/ms/questioneer');
let basePath;
if (isMsPath) {
// Для продакшна: используем /ms/questioneer
basePath = '/ms/questioneer';
} else {
// Для локальной разработки: используем текущий путь
basePath = window.location.pathname.split('/create')[0];
}
window.location.href = `${basePath}/admin/${result.data.adminLink}`;
} else {
showAlert(`Ошибка при создании опроса: ${result.error}`, 'Ошибка');