Skip to content

Commit bfc1416

Browse files
committed
add environment-based CORS proxy configuration
1 parent 941a8d0 commit bfc1416

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

.github/workflows/build-deploy-neurojsonio.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
# PUBLIC_URL="/" yarn build
2828
export PUBLIC_URL="/"
2929
export REACT_APP_API_URL="/api/v1"
30+
export REACT_APP_USE_CORS=false
3031
yarn build
3132
3233
- name: Copy JS libraries

.github/workflows/build-deploy-zodiac.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
# PUBLIC_URL="/dev/${{ env.BRANCH_NAME }}/" yarn build
3737
export PUBLIC_URL="/dev/${{ env.BRANCH_NAME }}/"
3838
export REACT_APP_API_URL="/dev/${{ env.BRANCH_NAME }}/api/v1"
39+
export REACT_APP_USE_CORS=true
3940
yarn build
4041
4142
- name: Copy JS libraries (jdata, bjdata etc.)

src/services/instance.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
22

3-
export const baseURL =
4-
process.env.REACT_APP_BACK_URL ??
5-
"https://cors.redoc.ly/https://neurojson.io:7777";
3+
// export const baseURL =
4+
// process.env.REACT_APP_BACK_URL ??
5+
// "https://cors.redoc.ly/https://neurojson.io:7777";
6+
7+
const needsCorsProxy =
8+
process.env.REACT_APP_USE_CORS === "true" ||
9+
process.env.NODE_ENV === "development";
10+
11+
const backendURL = "https://neurojson.io:7777";
12+
13+
export const baseURL = needsCorsProxy
14+
? `https://cors.redoc.ly/${backendURL}`
15+
: backendURL;
616

717
export const api: AxiosInstance = axios.create({
8-
baseURL,
9-
withCredentials: false,
18+
baseURL,
19+
withCredentials: false,
1020
});
1121

1222
api.interceptors.request.use((config) => {
13-
return config;
23+
return config;
1424
});
1525

1626
api.interceptors.response.use(
17-
(response: any) => response,
18-
async (error: { response: AxiosResponse; config: AxiosRequestConfig }) => {
19-
return Promise.reject(error);
20-
}
27+
(response: any) => response,
28+
async (error: { response: AxiosResponse; config: AxiosRequestConfig }) => {
29+
return Promise.reject(error);
30+
}
2131
);

0 commit comments

Comments
 (0)