forked from ahmedkamalio/migration-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
53 lines (47 loc) · 1.18 KB
/
api.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
const apiV8 = axios.create({
baseURL: process.env.V8_URL + "/" + process.env.V8_PROJECT_NAME,
headers: {
Authorization: `Bearer ${process.env.V8_TOKEN}`,
Cookie: `directus-${process.env.V8_PROJECT_NAME}-session=${process.env.V8_COOKIE_TOKEN}`,
},
});
apiV8.interceptors.response.use(
(response) => response,
(error) => {
const err = /**@type {import('axios').AxiosError}*/ (error);
throw Error(`
V8 =>
${err.config.url}
${err.config.params}
${JSON.stringify(err.config.params, null, 4)}
V8 <=
${err.response.status}
${JSON.stringify(err.response.data, null, 4)}
`);
}
);
const apiV9 = axios.create({
baseURL: process.env.V9_URL,
headers: {
Authorization: `Bearer ${process.env.V9_TOKEN}`,
},
});
apiV9.interceptors.response.use(
(response) => response,
(error) => {
const err = /**@type {import('axios').AxiosError}*/ (error);
throw Error(`
V9 =>
${err.config.url}
${err.config.params}
${JSON.stringify(err.config.params, null, 4)}
V9 <=
${err.response.status}
${JSON.stringify(err.response.data, null, 4)}
`);
}
);
export { apiV8, apiV9 };