import {Base64} from 'js-base64';
import website from '~src/config';
import {getToken} from '~src/api/util/auth';

export function getTokenHeader(text= false) {
    let headers = {};
    headers['Authorization'] = `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`;
    //让每个请求携带token
    const token = getToken()
    if (token) headers[website.tokenHeader] = 'bearer ' + token
    //headers中配置text请求
    if (text === true) {
        headers["Content-Type"] = "text/plain";
    }
    return headers;
}
