-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (30 loc) · 1.04 KB
/
index.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
'use strict'
const axios = require('axios');
var pathJoin = function (parts) {
const separator = '/';
parts = parts.map((part, index) => {
if (index) {
part = part.replace(new RegExp('^' + separator), '');
}
if (index !== parts.length - 1) {
part = part.replace(new RegExp(separator + '$'), '');
}
return part;
})
return parts.join(separator);
}
const requestHandler = (request) => {
// pull the settings out of the dom
const data = (document.querySelector("#__ClientContext")).value;
const appContext = JSON.parse(data);
appContext.headers = {};
appContext.headers['RequestVerificationToken'] = (document.querySelector("#__RequestVerificationToken")).value;
request.url = pathJoin([appContext.baseUrl, request.url]);
request.headers['RequestVerificationToken'] = appContext.headers['RequestVerificationToken'];
return request
}
axios.interceptors.request.use(
request => requestHandler(request)
);
const asiAxios = axios;
module.exports = asiAxios;