fix api url
This commit is contained in:
parent
91e225ff2f
commit
5f878047fd
30
script.js
30
script.js
@ -4,6 +4,9 @@ let events = { biot: [], ctpsr_main: [], gloves: [] };
|
||||
let currentFilter = 'все';
|
||||
let currentUser = null;
|
||||
|
||||
// URL бэкенда — меняется при каждом запуске
|
||||
const API_URL = 'https://code.vibe42.kz/vscode/genadis/kak-ya-mogu-skopirovat-chuzh/proxy/3000';
|
||||
|
||||
// Проверка авторизации при загрузке
|
||||
async function checkAuth() {
|
||||
const token = localStorage.getItem('token');
|
||||
@ -36,8 +39,7 @@ function showApp() {
|
||||
|
||||
async function login(username, password) {
|
||||
try {
|
||||
// Используем GET с query параметрами — proxy пропускает GET
|
||||
const res = await fetch('/service/login?username=' + encodeURIComponent(username) + '&password=' + encodeURIComponent(password), {
|
||||
const res = await fetch(API_URL + '/service/login?username=' + encodeURIComponent(username) + '&password=' + encodeURIComponent(password), {
|
||||
method: 'GET'
|
||||
});
|
||||
const data = await res.json();
|
||||
@ -47,6 +49,8 @@ async function login(username, password) {
|
||||
localStorage.setItem('userName', data.name);
|
||||
localStorage.setItem('userId', username);
|
||||
showApp();
|
||||
await loadEvents();
|
||||
render();
|
||||
} else {
|
||||
alert(data.error || 'Ошибка входа');
|
||||
}
|
||||
@ -54,6 +58,10 @@ async function login(username, password) {
|
||||
alert('Ошибка соединения: ' + e.message);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
alert('Ошибка соединения: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
function logout() {
|
||||
localStorage.removeItem('token');
|
||||
@ -88,7 +96,7 @@ function closeAdmin() {
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
const res = await fetch('/service/users', {
|
||||
const res = await fetch(API_URL + '/service/users', {
|
||||
headers: { 'Authorization': 'Bearer ' + currentUser.token }
|
||||
});
|
||||
if (!res.ok) {
|
||||
@ -121,7 +129,7 @@ document.getElementById('add-user-form').addEventListener('submit', async functi
|
||||
const password = document.getElementById('new-user-password').value.trim();
|
||||
|
||||
try {
|
||||
const res = await fetch('/service/users', {
|
||||
const res = await fetch(API_URL + '/service/users', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -145,7 +153,7 @@ document.getElementById('add-user-form').addEventListener('submit', async functi
|
||||
async function deleteUser(id) {
|
||||
if (!confirm('Удалить пользователя ' + id + '?')) return;
|
||||
try {
|
||||
const res = await fetch('/service/users/' + id, {
|
||||
const res = await fetch(API_URL + '/service/users/' + id, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': 'Bearer ' + currentUser.token }
|
||||
});
|
||||
@ -166,9 +174,9 @@ async function loadEvents() {
|
||||
try {
|
||||
const headers = { 'Authorization': 'Bearer ' + currentUser.token };
|
||||
const [biotRes, ctpsrRes, glovesRes] = await Promise.all([
|
||||
fetch('/service/events?tab=biot', { headers }),
|
||||
fetch('/service/events?tab=ctpsr_main', { headers }),
|
||||
fetch('/service/events?tab=gloves', { headers })
|
||||
fetch(API_URL + '/service/events?tab=biot', { headers }),
|
||||
fetch(API_URL + '/service/events?tab=ctpsr_main', { headers }),
|
||||
fetch(API_URL + '/service/events?tab=gloves', { headers })
|
||||
]);
|
||||
events.biot = await biotRes.json();
|
||||
events.ctpsr_main = await ctpsrRes.json();
|
||||
@ -436,7 +444,7 @@ function addNew() {
|
||||
async function deleteEvent(id) {
|
||||
if (!confirm('Вы уверены, что хотите удалить эту запись?')) return;
|
||||
var key = currentSubtab || currentTab;
|
||||
await fetch('/service/events/' + id + '?tab=' + key, {
|
||||
await fetch(API_URL + '/service/events/' + id + '?tab=' + key, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': 'Bearer ' + currentUser.token }
|
||||
});
|
||||
@ -487,7 +495,7 @@ document.getElementById('form').addEventListener('submit', async function(e) {
|
||||
|
||||
console.log('Data to save:', data);
|
||||
|
||||
var url = id ? '/service/events/' + id + '?tab=' + key : '/service/events?tab=' + key;
|
||||
var url = id ? API_URL + '/service/events/' + id + '?tab=' + key : API_URL + '/service/events?tab=' + key;
|
||||
console.log('POST to:', url);
|
||||
|
||||
try {
|
||||
@ -545,7 +553,7 @@ async function testApi() {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await fetch('/service/events?tab=biot', {
|
||||
const res = await fetch(API_URL + '/service/events?tab=biot', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user