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:
14
src/api.js
14
src/api.js
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user