-
Notifications
You must be signed in to change notification settings - Fork 37
/
config.js
33 lines (24 loc) · 1.35 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import axios from 'axios';
// this allows consuming create-react-app apps to inject the server address URL and context path (at build time)
// via the REACT_APP_SERVER_ADDRESS and REACT_APP_CONTEXT_PATH environment variables
// see: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables
// otherwise doesn't set the address and gets the context path by examining the window object
const REQUEST_TIMEOUT = 60000; // 60,000 ms or 60 sec
const serverAddress = (typeof process !== 'undefined' && typeof process.env !== 'undefined' &&
typeof process.env.REACT_APP_SERVER_ADDRESS !== 'undefined' && process.env.REACT_APP_SERVER_ADDRESS !== null) ?
process.env.REACT_APP_SERVER_ADDRESS : "";
const contextPath = (typeof process !== 'undefined' && typeof process.env !== 'undefined' &&
typeof process.env.REACT_APP_SERVER_CONTEXT_PATH !== 'undefined' && process.env.REACT_APP_SERVER_CONTEXT_PATH !== null) ?
process.env.REACT_APP_SERVER_CONTEXT_PATH : window.location.href.split('/')[3];
const apiBaseUrl = serverAddress
+ (contextPath.startsWith("/") ? '' : '/')
+ contextPath
+ "/ws/rest/v1";
export const axiosConfig = {
baseURL: apiBaseUrl,
timeout: REQUEST_TIMEOUT,
headers: {
'Content-Type': 'application/json'
}
};
export const axiosInstance = axios.create(axiosConfig);