Skip to content

Commit

Permalink
fix: lvsl bug when header not passed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoblanc committed Dec 1, 2024
1 parent 5d9d8cd commit 37c1fe8
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/app/provider/helper/http.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { HttpClient } from '@angular/common/http';
import { Injectable, NgZone } from '@angular/core';
import { Capacitor } from '@capacitor/core';
import { HTTP, HTTPResponse } from '@ionic-native/http/ngx';
import { from, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { runInZone } from '../../utils/run-in-zone.operator';
import { HttpClient } from "@angular/common/http";
import { Injectable, NgZone } from "@angular/core";
import { Capacitor } from "@capacitor/core";
import { HTTP, HTTPResponse } from "@ionic-native/http/ngx";
import { from, Observable } from "rxjs";
import { map } from "rxjs/operators";
import { runInZone } from "../../utils/run-in-zone.operator";

@Injectable({
providedIn: 'root'
providedIn: "root",
})
export class HttpService {


private develop: boolean; // L'indicateur de plateforme web ou native

constructor(private readonly nativeHttp: HTTP, private readonly developHttp: HttpClient, private readonly zone: NgZone) {
constructor(
private readonly nativeHttp: HTTP,
private readonly developHttp: HttpClient,
private readonly zone: NgZone
) {
this.develop = !Capacitor.isNativePlatform();
}

Expand All @@ -31,10 +33,10 @@ export class HttpService {
} else {
get$ = this.nativeGet(url);
}
console.warn("Ready to calll ", url);
return get$;
}


post<T>(url: string, body?: any, ignoreCors?: boolean): Observable<T> {
let post$;
if (this.develop || !ignoreCors) {
Expand All @@ -45,25 +47,28 @@ export class HttpService {
return post$;
}



/**
* La methode qui get en natif
* @param url L'url a get
*/
private nativeGet(url: string) {
return from(this.nativeHttp.get(url, {}, {}))
.pipe(
runInZone(this.zone),
map((data: HTTPResponse) => JSON.parse(data.data))
);
const headers: any = {
"Content-Type": "application/json",
};
headers["Accept"] = "application/json";
return from(this.nativeHttp.get(url, {}, headers)).pipe(
runInZone(this.zone),
map((data: HTTPResponse) => {
return JSON.parse(data.data);
})
);
}
/**
* La methode qui call en broswer
* @param url l'url a get
*/
private developGet(url: string) {
return this.developHttp.get(url,);
return this.developHttp.get(url);
}

/**
Expand All @@ -72,11 +77,10 @@ export class HttpService {
* @param body le body a poster
*/
private nativePost(url: string, body?: any) {

return from(this.nativeHttp.post(url, body, {}))
.pipe(
runInZone(this.zone),
map((data: HTTPResponse) => JSON.parse(data.data)));
return from(this.nativeHttp.post(url, body, {})).pipe(
runInZone(this.zone),
map((data: HTTPResponse) => JSON.parse(data.data))
);
}
/**
* La methode qui call en broswer
Expand All @@ -86,6 +90,4 @@ export class HttpService {
private developPost(url: string, body?: any) {
return this.developHttp.post(url, body);
}


}

0 comments on commit 37c1fe8

Please sign in to comment.