fixed cors

This commit is contained in:
2023-08-06 00:44:27 +03:00
parent fdcba863c2
commit 7d4bb47a53
5 changed files with 29 additions and 14 deletions

View File

@@ -3,9 +3,10 @@ import { routes } from './routes.js';
let DEBUG = true;
window.DEBUG = DEBUG;
let SERVER_URL;
let SERVER_HOST;
if (DEBUG) SERVER_HOST = 'localhost';
else SERVER_HOST = 'a2s.su';
window.SERVER_HOST = SERVER_HOST;
/* main */
window.onload = function () {
@@ -75,12 +76,18 @@ const location_handler = async () => {
};
function get_from_api(callback, api_method = '', params = {}) {
respone = '';
if (api_method == '') {
console.log('wrong method');
} else {
fetch(`http://${SERVER_HOST}:3000/api/v1.0/${api_method}`)
let url = `http://${SERVER_HOST}:3000/api/v1.0/${api_method}`;
let opts = {
method: 'get',
headers: {
'Content-Type': 'application/json',
},
};
fetch(url, opts)
.then((response) => {
return response.json();
})