Skip to content

Commit 78de150

Browse files
feat: implement API request infrastructure including endpoint constants, authentication interceptor, and URL utility helpers
1 parent 7b675ea commit 78de150

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

frontend/src/core/constants/api-endpoints.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { linkServerConvert } from "@shared/lib";
1+
import { linkCombine, linkServerConvert } from "@shared/lib";
22

33
export const API_ENDPOINTS = {
44
VEILS: {
55
URL: "veils",
66
COUNT: "veils/count",
7-
URL_BY_ID: (id: string) => linkServerConvert(API_ENDPOINTS.VEILS.URL, id),
7+
URL_BY_ID: (id: string) => linkCombine(API_ENDPOINTS.VEILS.URL, id),
88
},
99
TREATMENTS: {
1010
URL: "treatments",
1111
COUNT: "treatments/count",
12-
URL_BY_ID: (id: string) => linkServerConvert(API_ENDPOINTS.TREATMENTS.URL, id),
12+
URL_BY_ID: (id: string) => linkCombine(API_ENDPOINTS.TREATMENTS.URL, id),
1313
},
1414
GALLERY: {
1515
URL: "gallery",
1616
COUNT: "gallery/count",
17-
URL_BY_ID: (id: string) => linkServerConvert(API_ENDPOINTS.GALLERY.URL, id),
17+
URL_BY_ID: (id: string) => linkCombine(API_ENDPOINTS.GALLERY.URL, id),
1818
},
1919
AUTH: {
2020
SIGNIN: "auth/login",
@@ -32,6 +32,6 @@ export const API_ENDPOINTS = {
3232
USERS: {
3333
URL: "users",
3434
COUNT: "users/count",
35-
URL_BY_ID: (id: string) => linkServerConvert(API_ENDPOINTS.USERS.URL, id),
35+
URL_BY_ID: (id: string) => linkCombine(API_ENDPOINTS.USERS.URL, id),
3636
}
3737
} as const;

frontend/src/core/interceptors/api.interceptor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { catchError, of, retry } from "rxjs";
66

77
export const apiInterceptor: HttpInterceptorFn = (req, next) => {
88
const accessToken = sessionStorage.getItem("access_token");
9-
const router = inject(Router);
10-
console.log('Request URL: ', linkServerConvert(req.url));
11-
9+
const router = inject(Router);
1210

1311
if (!accessToken) {
1412
const apiReq = req.clone({

frontend/src/shared/lib/link.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ export function linkMerge(...link: string[]): string {
1818
}
1919

2020
export function getApiBaseUrl(): string {
21-
if (window.location.port === '4200') {
21+
const port = window.location.port;
22+
const isProduction = environment.production;
23+
24+
if (port && !isProduction) {
2225
return environment.apiUrl;
2326
}
2427

25-
if ((window as any).API_URL) {
28+
if (!port && isProduction) {
2629
return (window as any).API_URL;
2730
}
2831

0 commit comments

Comments
 (0)