Skip to content

Commit c6357fc

Browse files
committed
Fix android web
1 parent 0134a76 commit c6357fc

File tree

2 files changed

+47
-32
lines changed

2 files changed

+47
-32
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="io.ionic.starter">
44

55
<application
6+
android:usesCleartextTraffic="true"
67
android:allowBackup="true"
78
android:icon="@mipmap/ic_launcher"
89
android:label="@string/app_name"

src/app/api.service.ts

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Injectable} from '@angular/core';
22
import {Storage} from '@ionic/storage-angular';
3+
import { CapacitorHttp } from '@capacitor/core';
34

45
@Injectable({
56
providedIn: 'root'
@@ -37,14 +38,15 @@ export class ApiService {
3738
console.log('signIn');
3839
let url = new URL(this.endpoint + '/api/auth/signin');
3940

40-
return fetch(url, {
41+
return CapacitorHttp.request({
42+
url: url.toString(),
4143
method: 'POST',
4244
headers: this.headers,
43-
body: JSON.stringify({
45+
data: JSON.stringify({
4446
email: email,
4547
password: password
4648
})
47-
}).then(res => res.json()).then(res => {
49+
}).then(res => res.data).then(res => {
4850
if (res.accessToken) {
4951
this.setToken(res.accessToken);
5052
}
@@ -56,15 +58,16 @@ export class ApiService {
5658
console.log('register');
5759
let url = new URL(this.endpoint + '/api/auth/signup');
5860

59-
return fetch(url, {
61+
return CapacitorHttp.request({
62+
url: url.toString(),
6063
method: 'POST',
6164
headers: this.headers,
62-
body: JSON.stringify({
65+
data: JSON.stringify({
6366
email: email,
6467
username: username,
6568
password: password
6669
})
67-
}).then(res => res.json());
70+
}).then(res => res.data);
6871
}
6972

7073
public isLoggedIn() {
@@ -79,10 +82,11 @@ export class ApiService {
7982
if (this.accessToken)
8083
url.searchParams.append('accessToken', this.accessToken);
8184

82-
return fetch(url, {
85+
return CapacitorHttp.request({
86+
url: url.toString(),
8387
method: 'GET',
8488
headers: this.headers,
85-
}).then(res => res.json()).then(res => {
89+
}).then(res => res.data).then(res => {
8690
if (res.id) {
8791
this.id = res.id;
8892
this.username = res.username;
@@ -117,20 +121,22 @@ export class ApiService {
117121
this.username = "";
118122
this.email = "";
119123

120-
return fetch(url, {
124+
return CapacitorHttp.request({
125+
url: url.toString(),
121126
method: 'POST',
122127
headers: this.headers
123-
}).then(res => res.json());
128+
}).then(res => res.data);
124129
}
125130

126131
public searchSets(search: string, count: number = 10) {
127132
console.log('searchSets');
128133
let url = new URL(this.endpoint + '/api/set/search/' + search + "/" + count);
129134

130-
return fetch(url, {
135+
return CapacitorHttp.request({
136+
url:url.toString(),
131137
method: 'GET',
132138
headers: this.headers,
133-
}).then(res => res.json());
139+
}).then(res => res.data);
134140
}
135141

136142
public getUserSets() {
@@ -140,10 +146,11 @@ export class ApiService {
140146
if (this.accessToken)
141147
url.searchParams.append('accessToken', this.accessToken);
142148

143-
return fetch(url, {
149+
return CapacitorHttp.request({
150+
url: url.toString(),
144151
method: 'GET',
145152
headers: this.headers,
146-
}).then(res => res.json());
153+
}).then(res => res.data);
147154
}
148155

149156
public createSet(set: any) {
@@ -153,11 +160,12 @@ export class ApiService {
153160
if (this.accessToken)
154161
url.searchParams.append('accessToken', this.accessToken);
155162

156-
return fetch(url, {
163+
return CapacitorHttp.request({
164+
url: url.toString(),
157165
method: 'POST',
158166
headers: this.headers,
159-
body: JSON.stringify(set)
160-
}).then(res => res.json());
167+
data: JSON.stringify(set)
168+
}).then(res => res.data);
161169
}
162170

163171
public updateSet(id: number, set: any) {
@@ -167,11 +175,12 @@ export class ApiService {
167175
if (this.accessToken)
168176
url.searchParams.append('accessToken', this.accessToken);
169177

170-
return fetch(url, {
178+
return CapacitorHttp.request({
179+
url: url.toString(),
171180
method: 'PUT',
172181
headers: this.headers,
173-
body: JSON.stringify(set)
174-
}).then(res => res.json());
182+
data: JSON.stringify(set)
183+
}).then(res => res.data);
175184
}
176185

177186
public deleteSet(id: string) {
@@ -181,20 +190,22 @@ export class ApiService {
181190
if (this.accessToken)
182191
url.searchParams.append('accessToken', this.accessToken);
183192

184-
return fetch(url, {
193+
return CapacitorHttp.request({
194+
url: url.toString(),
185195
method: 'DELETE',
186196
headers: this.headers,
187-
}).then(res => res.json());
197+
}).then(res => res.data);
188198
}
189199

190200
public getSet(id: string) {
191201
console.log('getSet');
192202
let url = new URL(this.endpoint + '/api/set/' + id);
193203

194-
return fetch(url, {
204+
return CapacitorHttp.request({
205+
url: url.toString(),
195206
method: 'GET',
196207
headers: this.headers,
197-
}).then(res => res.json());
208+
}).then(res => res.data);
198209
}
199210

200211
public getUserStats(id: string) {
@@ -204,10 +215,11 @@ export class ApiService {
204215
if (this.accessToken)
205216
url.searchParams.append('accessToken', this.accessToken);
206217

207-
return fetch(url, {
218+
return CapacitorHttp.request({
219+
url: url.toString(),
208220
method: 'GET',
209221
headers: this.headers,
210-
}).then(res => res.json());
222+
}).then(res => res.data);
211223
}
212224

213225
public updateUserStats(id: string, card: string, type: string) {
@@ -217,13 +229,14 @@ export class ApiService {
217229
if (this.accessToken)
218230
url.searchParams.append('accessToken', this.accessToken);
219231

220-
return fetch(url, {
232+
return CapacitorHttp.request({
233+
url: url.toString(),
221234
method: 'PUT',
222235
headers: this.headers,
223-
body: JSON.stringify({
236+
data: JSON.stringify({
224237
type: type
225238
})
226-
}).then(res => res.json());
239+
}).then(res => res.data);
227240
}
228241

229242
public updateUserStared(id: string, card: string, stared: boolean) {
@@ -233,13 +246,14 @@ export class ApiService {
233246
if (this.accessToken)
234247
url.searchParams.append('accessToken', this.accessToken);
235248

236-
return fetch(url, {
249+
return CapacitorHttp.request({
250+
url: url.toString(),
237251
method: 'PUT',
238252
headers: this.headers,
239-
body: JSON.stringify({
253+
data: JSON.stringify({
240254
stared: stared
241255
})
242-
}).then(res => res.json());
256+
}).then(res => res.data);
243257
}
244258

245259
private setToken(token: string) {

0 commit comments

Comments
 (0)