|
Last change
on this file since d30d820 was d30d820, checked in by MBK <marija.karapandzova@…>, 4 months ago |
|
Add pages and routing for medical recors, medical reports and referrals with api services
|
-
Property mode
set to
100644
|
|
File size:
746 bytes
|
| Line | |
|---|
| 1 | import axios from 'axios';
|
|---|
| 2 |
|
|---|
| 3 | const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:8080/api';
|
|---|
| 4 |
|
|---|
| 5 | const apiClient = axios.create({
|
|---|
| 6 | baseURL: API_URL,
|
|---|
| 7 | headers: {
|
|---|
| 8 | 'Content-Type': 'application/json',
|
|---|
| 9 | },
|
|---|
| 10 | });
|
|---|
| 11 |
|
|---|
| 12 | // Request interceptor to add JWT token
|
|---|
| 13 | apiClient.interceptors.request.use(
|
|---|
| 14 | config => {
|
|---|
| 15 | const token = localStorage.getItem('token');
|
|---|
| 16 | if (token) {
|
|---|
| 17 | config.headers.Authorization = `Bearer ${token}`;
|
|---|
| 18 | }
|
|---|
| 19 | return config;
|
|---|
| 20 | },
|
|---|
| 21 | error => Promise.reject(error)
|
|---|
| 22 | );
|
|---|
| 23 |
|
|---|
| 24 | // Error handling interceptor
|
|---|
| 25 | apiClient.interceptors.response.use(
|
|---|
| 26 | response => response,
|
|---|
| 27 | error => {
|
|---|
| 28 | console.error('API Error:', error.response?.data || error.message);
|
|---|
| 29 | return Promise.reject(error);
|
|---|
| 30 | }
|
|---|
| 31 | );
|
|---|
| 32 |
|
|---|
| 33 | export default apiClient;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.