generated from VLADIMIR/template_frontend
ups
This commit is contained in:
+15
-12
@@ -1,6 +1,8 @@
|
||||
import type { Game, Team } from './models'
|
||||
import { UnauthorizedError } from './UnauthorizedError'
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL;
|
||||
|
||||
export const apiGetTeam = async (login: string, password: string): Promise<Team> => {
|
||||
try {
|
||||
const response = await fetch(getApiUrl('/team'), {
|
||||
@@ -25,15 +27,15 @@ export const apiGetTeam = async (login: string, password: string): Promise<Team>
|
||||
|
||||
export const apiLetsgo = async (login: string, password: string, place: string) => {
|
||||
try {
|
||||
const response = await fetch(getApiUrl("/team/actions"), {
|
||||
method: "POST",
|
||||
const response = await fetch(getApiUrl('/team/actions'), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"X-Id": encodeUTF8ToBase64(login),
|
||||
"X-Password": password
|
||||
'X-Id': encodeUTF8ToBase64(login),
|
||||
'X-Password': password,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"place": place
|
||||
})
|
||||
place: place,
|
||||
}),
|
||||
})
|
||||
if (response.status === 401) {
|
||||
throw new UnauthorizedError('Ошибка авторизации')
|
||||
@@ -50,7 +52,7 @@ export const apiLetsgo = async (login: string, password: string, place: string)
|
||||
|
||||
export const apiGetGame = async (login: string, password: string): Promise<Game> => {
|
||||
try {
|
||||
const response = await fetch(getApiUrl("/game"), {
|
||||
const response = await fetch(getApiUrl('/game'), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Id': encodeUTF8ToBase64(login),
|
||||
@@ -70,13 +72,14 @@ export const apiGetGame = async (login: string, password: string): Promise<Game>
|
||||
}
|
||||
}
|
||||
|
||||
export function getApiUrl(path: string) {
|
||||
// const url = 'http://' + window.location.host.split(':')[0] + ':8090' + path
|
||||
// return url
|
||||
return 'https://evening-detective-api.crabs-games.art' + path
|
||||
function getApiUrl(path: string) {
|
||||
if (API_URL === '') {
|
||||
return 'http://' + window.location.host.split(':')[0] + ':8090' + path
|
||||
}
|
||||
return API_URL + path
|
||||
}
|
||||
|
||||
export function encodeUTF8ToBase64(s: string) {
|
||||
function encodeUTF8ToBase64(s: string) {
|
||||
return btoa(
|
||||
encodeURIComponent(s).replace(/%([0-9A-F]{2})/g, (_, p1) =>
|
||||
String.fromCharCode(parseInt(p1, 16)),
|
||||
|
||||
Reference in New Issue
Block a user