Automatic choice of production and dev mode

This commit is contained in:
DomySh
2022-06-15 09:11:27 +02:00
parent 3ec0879608
commit 8eb3403a79
6 changed files with 53 additions and 56 deletions

View File

@@ -5,15 +5,13 @@ import { GeneralStats, Service, ServiceAddForm, ServerResponse, RegexFilter, not
var Buffer = require('buffer').Buffer
const DEBUG = false
const custom_url = DEBUG?"http://127.0.0.1:8080":""
const custom_url = (!process.env.NODE_ENV || process.env.NODE_ENV === 'development')?"http://127.0.0.1:8080":""
export async function getapi(path:string):Promise<any>{
return await new Promise((resolve, reject) => {
fetch(`${custom_url}/api/${path}`,{credentials: "same-origin"})
.then(res => {
if(res.status == 401) window.location.reload()
if(res.status === 401) window.location.reload()
if(!res.ok) reject(res.statusText)
res.json().then( res => resolve(res) ).catch( err => reject(err))
})
@@ -34,7 +32,7 @@ export async function postapi(path:string,data:any):Promise<any>{
},
body: JSON.stringify(data)
}).then(res => {
if(res.status == 401) window.location.reload()
if(res.status === 401) window.location.reload()
if(!res.ok) reject(res.statusText)
res.json().then( res => resolve(res) ).catch( err => reject(err))
})