|
@@ -1,52 +1,78 @@
|
|
|
-import $ from 'jquery'
|
|
|
|
|
-
|
|
|
|
|
-export const V2 = (url, data) => {
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type:"POST",
|
|
|
|
|
- url:url,
|
|
|
|
|
- data: JSON.stringify(data),
|
|
|
|
|
- contentType: 'application/json',
|
|
|
|
|
- success: function(res) {
|
|
|
|
|
- console.log('jquery resp',res);
|
|
|
|
|
- console.log("Added");
|
|
|
|
|
- },
|
|
|
|
|
- error: function(xhr, status, err) {
|
|
|
|
|
- console.error(xhr, status, err.toString());
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-export const V1 = async (url, body) => {
|
|
|
|
|
- let response = await fetch(url, {
|
|
|
|
|
- method: 'POST',
|
|
|
|
|
- headers: {
|
|
|
|
|
- 'Accept': 'application/json',
|
|
|
|
|
- 'Content-Type': 'application/json'
|
|
|
|
|
- },
|
|
|
|
|
- body : JSON.stringify(body)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- let req = await response.json();
|
|
|
|
|
- console.log('register request',req )
|
|
|
|
|
-}
|
|
|
|
|
|
|
+import axios from 'axios';
|
|
|
|
|
|
|
|
export class Service {
|
|
export class Service {
|
|
|
|
|
|
|
|
constructor(path){
|
|
constructor(path){
|
|
|
- this.base_url = 'http://psicoadmin.ditca.org:8081'
|
|
|
|
|
|
|
+ this.base_url = 'http://204.48.25.93:8081'
|
|
|
this.url = this.base_url + path
|
|
this.url = this.base_url + path
|
|
|
|
|
+ // this.base_url = 'http://psicoadmin.ditca.org:8081'
|
|
|
// this.api = 'http://204.48.25.93:8081/user?user=patrik&password=12345'
|
|
// this.api = 'http://204.48.25.93:8081/user?user=patrik&password=12345'
|
|
|
// this.api = 'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345'
|
|
// this.api = 'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async post(body){
|
|
|
|
|
- console.log('body >> ', body)
|
|
|
|
|
|
|
+ async get(token){
|
|
|
|
|
+ return axios.get(this.url, {
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'Authorization': `Bearer ${token}`
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .then((res) => {
|
|
|
|
|
+ return res;
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((error) => {
|
|
|
|
|
+ return error;
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ async get_(token){
|
|
|
|
|
+
|
|
|
|
|
+ console.log('MY TOKEN ::', token)
|
|
|
|
|
+ console.log('MY URL ::', this.url)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
let response = await fetch(this.url, {
|
|
let response = await fetch(this.url, {
|
|
|
|
|
+ headers: new Headers({
|
|
|
|
|
+ // "Hwjst" : location.hostname,
|
|
|
|
|
+ 'Authorization': 'Bearer '+ token,
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ return await response.json();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async post(body, token){
|
|
|
|
|
+
|
|
|
|
|
+ if(!token){
|
|
|
|
|
+ let response = await fetch(this.url, {
|
|
|
|
|
+ method: "POST",
|
|
|
|
|
+ body : JSON.stringify(body)
|
|
|
|
|
+ })
|
|
|
|
|
+ return await response.json();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const MyHeaders ={
|
|
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
|
|
+ 'Authorization': 'Bearer '+ token
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log('MY TOKEN ::', token)
|
|
|
|
|
+ console.log('MY URL ::', this.url)
|
|
|
|
|
+ console.log('MY HEADER ::', MyHeaders)
|
|
|
|
|
+
|
|
|
|
|
+ let response = await fetch(this.url, {
|
|
|
|
|
+ credentials: 'include',
|
|
|
method: "POST",
|
|
method: "POST",
|
|
|
|
|
+ mode: 'cors',
|
|
|
|
|
+ cache: 'default',
|
|
|
|
|
+ headers: MyHeaders,
|
|
|
body : JSON.stringify(body)
|
|
body : JSON.stringify(body)
|
|
|
})
|
|
})
|
|
|
return await response.json();
|
|
return await response.json();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|