-
Notifications
You must be signed in to change notification settings - Fork 2
/
axios.js
52 lines (50 loc) · 1.35 KB
/
axios.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
export default function (
{
app,
$axios,
$config: {
staticEndpoint,
staticBaseToReplace,
dynamicEndpoint,
backendEndpoint,
},
},
inject
) {
const staticCatalog = $axios.create();
staticCatalog.setBaseURL(staticEndpoint);
staticCatalog.baseToReplace = staticBaseToReplace;
// Add ".json" to all requests going to the static catalog
staticCatalog.onRequest((config) => {
const newUrl = `${config.url}.json`;
return {
...config,
url: newUrl,
};
});
inject("staticCatalog", staticCatalog);
const dynamicCatalog = $axios.create();
dynamicCatalog.setBaseURL(dynamicEndpoint);
// Add "f=json" query param to all requests going to the dynamic catalog
dynamicCatalog.onRequest((config) => {
const newUrl = `${config.url}&f=json`;
return {
...config,
url: newUrl,
};
});
inject("dynamicCatalog", dynamicCatalog);
const metadataBackend = $axios.create();
metadataBackend.setBaseURL(backendEndpoint);
// TEMP until this comes from the backend protection layer
metadataBackend.onRequest(() => {
if (app.$auth?.loggedIn) {
metadataBackend.setHeader("X-User", app.$auth.user.email);
metadataBackend.setHeader(
"X-OSCDataOwner",
`${!!app.$auth.user.OSCDataOwner}`
);
}
});
inject("metadataBackend", metadataBackend);
}