| 1 | import React from 'react';
|
|---|
| 2 | import ReactDOM from 'react-dom/client';
|
|---|
| 3 | import './index.css';
|
|---|
| 4 | import reportWebVitals from './reportWebVitals';
|
|---|
| 5 | import {redirect} from "react-router-dom";
|
|---|
| 6 |
|
|---|
| 7 | import 'bootstrap/dist/css/bootstrap.min.css';
|
|---|
| 8 | import 'react-toastify/dist/ReactToastify.css';
|
|---|
| 9 |
|
|---|
| 10 | import axios from "axios";
|
|---|
| 11 | import {AuthProvider} from "./configurations/AuthContext";
|
|---|
| 12 | import {toast} from "react-toastify";
|
|---|
| 13 | import App from "./App";
|
|---|
| 14 |
|
|---|
| 15 | const credentials = JSON.parse(sessionStorage.getItem("authData"));
|
|---|
| 16 |
|
|---|
| 17 | axios.defaults.baseURL = 'http://localhost:8080/api';
|
|---|
| 18 | axios.defaults.headers.post['Content-Type'] = 'application/json';
|
|---|
| 19 | if (credentials) {
|
|---|
| 20 | axios.defaults.headers.common['Authorization'] = credentials.userCredential;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | axios.interceptors.response.use((response) => {
|
|---|
| 24 | if (response.config.method !== "get") {
|
|---|
| 25 | toast.success("Success", {
|
|---|
| 26 | toastId: "custom-id-success"
|
|---|
| 27 | })
|
|---|
| 28 | }
|
|---|
| 29 | return response;
|
|---|
| 30 | }, function (error) {
|
|---|
| 31 | console.log(error);
|
|---|
| 32 | toast.error(error.message)
|
|---|
| 33 |
|
|---|
| 34 | if (error.response.status === 404) {
|
|---|
| 35 | redirect('/');
|
|---|
| 36 | }
|
|---|
| 37 | return Promise.reject(error.response);
|
|---|
| 38 | });
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | const root = ReactDOM.createRoot(document.getElementById('root'));
|
|---|
| 44 | root.render(
|
|---|
| 45 | <AuthProvider>
|
|---|
| 46 | <App/>
|
|---|
| 47 | </AuthProvider>
|
|---|
| 48 | );
|
|---|
| 49 |
|
|---|
| 50 | // If you want to start measuring performance in your app, pass a function
|
|---|
| 51 | // to log results (for example: reportWebVitals(console.log))
|
|---|
| 52 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|---|
| 53 | reportWebVitals();
|
|---|