If configs apiUrl not defined fallback to origin.

Also removed dependency of login and register to redirect response from
server. Now we send json data with status = 200 when successfully
login/registered.
Username input element also is set to not capitalize input.
This commit is contained in:
2020-03-10 19:00:08 +01:00
parent 410dfcca44
commit fc3b9d3eb5
3 changed files with 24 additions and 37 deletions

View File

@@ -1,4 +1,4 @@
const BASE_URL = __APIURL__ || "http://localhost:30030/";
const BASE_URL = __APIURL__ || window.location.origin;
const statistics = () => {
const url = new URL('/api/purchase/statistics', BASE_URL)
@@ -119,17 +119,13 @@ const login = (username, password) => {
"Content-Type": "application/json"
},
method: "POST",
redirect: "follow",
body: JSON.stringify({ username, password })
}
return fetch(url.href, options)
.then(resp => {
if (resp.ok) {
if (resp.bodyUsed)
return resp.json()
else
return resp
return resp.json()
} else {
return handleErrors(resp)
}
@@ -143,17 +139,13 @@ const register = (username, password) => {
"Content-Type": "application/json"
},
method: "POST",
redirect: 'follow',
body: JSON.stringify({ username, password })
}
return fetch(url.href, options)
.then(resp => {
if (resp.ok) {
if (resp.bodyUsed)
return resp.json()
else
return resp
return resp.json()
} else {
return handleErrors(resp)
}