mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-17 02:33:07 +03:00
initial commit
This commit is contained in:
23
frontend/src/lib/services/api-service.ts
Normal file
23
frontend/src/lib/services/api-service.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { env } from '$env/dynamic/public';
|
||||
import axios from 'axios';
|
||||
|
||||
abstract class APIService {
|
||||
baseURL: string = '/api';
|
||||
api = axios.create({
|
||||
withCredentials: true
|
||||
});
|
||||
|
||||
constructor(accessToken?: string) {
|
||||
if (accessToken) {
|
||||
this.api.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
|
||||
} else {
|
||||
this.api.defaults.baseURL = '/api';
|
||||
}
|
||||
if (!browser) {
|
||||
this.api.defaults.baseURL = (env.PUBLIC_APP_URL ?? 'http://localhost') + '/api';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default APIService;
|
||||
Reference in New Issue
Block a user