|
@@ -1,52 +1,78 @@
|
1
|
|
-import $ from 'jquery'
|
2
|
|
-
|
3
|
|
-export const V2 = (url, data) => {
|
4
|
|
- $.ajax({
|
5
|
|
- type:"POST",
|
6
|
|
- url:url,
|
7
|
|
- data: JSON.stringify(data),
|
8
|
|
- contentType: 'application/json',
|
9
|
|
- success: function(res) {
|
10
|
|
- console.log('jquery resp',res);
|
11
|
|
- console.log("Added");
|
12
|
|
- },
|
13
|
|
- error: function(xhr, status, err) {
|
14
|
|
- console.error(xhr, status, err.toString());
|
15
|
|
- }
|
16
|
|
- })
|
17
|
|
-}
|
18
|
|
-
|
19
|
|
-export const V1 = async (url, body) => {
|
20
|
|
- let response = await fetch(url, {
|
21
|
|
- method: 'POST',
|
22
|
|
- headers: {
|
23
|
|
- 'Accept': 'application/json',
|
24
|
|
- 'Content-Type': 'application/json'
|
25
|
|
- },
|
26
|
|
- body : JSON.stringify(body)
|
27
|
|
- })
|
28
|
|
-
|
29
|
|
- let req = await response.json();
|
30
|
|
- console.log('register request',req )
|
31
|
|
-}
|
|
1
|
+import axios from 'axios';
|
32
|
2
|
|
33
|
3
|
export class Service {
|
34
|
4
|
|
35
|
5
|
constructor(path){
|
36
|
|
- this.base_url = 'http://psicoadmin.ditca.org:8081'
|
|
6
|
+ this.base_url = 'http://204.48.25.93:8081'
|
37
|
7
|
this.url = this.base_url + path
|
|
8
|
+ // this.base_url = 'http://psicoadmin.ditca.org:8081'
|
38
|
9
|
// this.api = 'http://204.48.25.93:8081/user?user=patrik&password=12345'
|
39
|
10
|
// this.api = 'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345'
|
40
|
11
|
}
|
41
|
12
|
|
42
|
|
- async post(body){
|
43
|
|
- console.log('body >> ', body)
|
|
13
|
+ async get(token){
|
|
14
|
+ return axios.get(this.url, {
|
|
15
|
+ headers: {
|
|
16
|
+ 'Authorization': `Bearer ${token}`
|
|
17
|
+ }
|
|
18
|
+ })
|
|
19
|
+ .then((res) => {
|
|
20
|
+ return res;
|
|
21
|
+ })
|
|
22
|
+ .catch((error) => {
|
|
23
|
+ return error;
|
|
24
|
+ })
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+ async get_(token){
|
|
29
|
+
|
|
30
|
+ console.log('MY TOKEN ::', token)
|
|
31
|
+ console.log('MY URL ::', this.url)
|
|
32
|
+
|
|
33
|
+
|
44
|
34
|
let response = await fetch(this.url, {
|
|
35
|
+ headers: new Headers({
|
|
36
|
+ // "Hwjst" : location.hostname,
|
|
37
|
+ 'Authorization': 'Bearer '+ token,
|
|
38
|
+ })
|
|
39
|
+ })
|
|
40
|
+ return await response.json();
|
|
41
|
+
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ async post(body, token){
|
|
45
|
+
|
|
46
|
+ if(!token){
|
|
47
|
+ let response = await fetch(this.url, {
|
|
48
|
+ method: "POST",
|
|
49
|
+ body : JSON.stringify(body)
|
|
50
|
+ })
|
|
51
|
+ return await response.json();
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+ const MyHeaders ={
|
|
56
|
+ 'Content-Type': 'application/json',
|
|
57
|
+ 'Authorization': 'Bearer '+ token
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ console.log('MY TOKEN ::', token)
|
|
61
|
+ console.log('MY URL ::', this.url)
|
|
62
|
+ console.log('MY HEADER ::', MyHeaders)
|
|
63
|
+
|
|
64
|
+ let response = await fetch(this.url, {
|
|
65
|
+ credentials: 'include',
|
45
|
66
|
method: "POST",
|
|
67
|
+ mode: 'cors',
|
|
68
|
+ cache: 'default',
|
|
69
|
+ headers: MyHeaders,
|
46
|
70
|
body : JSON.stringify(body)
|
47
|
71
|
})
|
48
|
72
|
return await response.json();
|
|
73
|
+
|
49
|
74
|
}
|
50
|
75
|
|
|
76
|
+
|
51
|
77
|
}
|
52
|
78
|
|