Hammaad
commited on
Commit
•
ca3a82b
1
Parent(s):
b7b370e
Added the environment files
Browse files
src/app/core/services/request-manager.service.ts
CHANGED
@@ -1,36 +1,54 @@
|
|
1 |
import { Injectable } from "@angular/core";
|
2 |
-
import { HttpClient } from '@angular/common/http';
|
3 |
import { Observable } from "rxjs";
|
4 |
-
import { environment } from "src/environments/environment";
|
|
|
5 |
@Injectable({
|
6 |
-
|
7 |
-
|
8 |
-
export class RequestManagerService{
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
}
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
}
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
|
|
1 |
import { Injectable } from "@angular/core";
|
2 |
+
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
3 |
import { Observable } from "rxjs";
|
4 |
+
import { environment } from "src/environments/environment.prod";
|
5 |
+
|
6 |
@Injectable({
|
7 |
+
providedIn: 'root'
|
8 |
+
})
|
9 |
+
export class RequestManagerService {
|
10 |
+
private apiUrl = environment.identityServerURL;
|
11 |
+
|
12 |
+
constructor(private http: HttpClient) {}
|
13 |
+
|
14 |
+
// Helper function to get headers with Authorization
|
15 |
+
private getHeaders(): HttpHeaders {
|
16 |
+
// The actual token, extracted from your URL or environment (adjust as needed)
|
17 |
+
const url = "https://ironone-atrad-atradgpt-back-end.hf.space/api/v1/sqwegrwWSAHahf_hf_iFCkXksUTPpVjzzExoaIBmfGelKtvkLNqG/BmfGelKtvkLNqG";
|
18 |
+
const token = url.split('sqwegrwWSAHahf_')[1].split('/')[0]; // Extract token after the prefix, ignoring the rest
|
19 |
+
console.log('Extracted token:', token); // To verify it's correct
|
20 |
+
|
21 |
+
return new HttpHeaders({
|
22 |
+
'Authorization': `Bearer ${token}`, // Ensure Bearer token is correct
|
23 |
+
'Content-Type': 'application/json'
|
24 |
+
});
|
25 |
+
}
|
26 |
+
|
27 |
+
// GET request with Authorization header
|
28 |
+
public get(endpoint: string): Observable<any> {
|
29 |
+
const url = `${this.apiUrl}/${endpoint}`;
|
30 |
+
const headers = this.getHeaders();
|
31 |
+
return this.http.get(url, { headers });
|
32 |
+
}
|
33 |
+
|
34 |
+
// POST request with Authorization header
|
35 |
+
public post(endpoint: string, data: any): Observable<any> {
|
36 |
+
const url = `${this.apiUrl}/${endpoint}`;
|
37 |
+
const headers = this.getHeaders();
|
38 |
+
return this.http.post(url, data, { headers });
|
39 |
+
}
|
40 |
+
|
41 |
+
// PUT request with Authorization header
|
42 |
+
public put(endpoint: string, data: any): Observable<any> {
|
43 |
+
const url = `${this.apiUrl}/${endpoint}`;
|
44 |
+
const headers = this.getHeaders();
|
45 |
+
return this.http.put(url, data, { headers });
|
46 |
+
}
|
47 |
+
|
48 |
+
// DELETE request with Authorization header
|
49 |
+
public delete(endpoint: string): Observable<any> {
|
50 |
+
const url = `${this.apiUrl}/${endpoint}`;
|
51 |
+
const headers = this.getHeaders();
|
52 |
+
return this.http.delete(url, { headers });
|
53 |
+
}
|
54 |
}
|
src/environments/environment.prod.ts
CHANGED
@@ -1,7 +1,4 @@
|
|
1 |
export const environment = {
|
2 |
production: true,
|
3 |
-
identityServerURL: '
|
4 |
-
|
5 |
-
// identityServerURL: 'http://222.165.180.215:8000' // for Network
|
6 |
-
// identityServerURL: 'api' // for Network
|
7 |
-
};
|
|
|
1 |
export const environment = {
|
2 |
production: true,
|
3 |
+
identityServerURL: 'https://ironone-atrad-atradgpt-back-end.hf.space/api/v1',
|
4 |
+
};
|
|
|
|
|
|