Subdirectory: use instance static files from subdirectory
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
/**
|
||||
* API: HTTP client and utilities.
|
||||
* @see {@link https://github.com/axios/axios}
|
||||
* @module soapbox/api
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
import axios from 'axios';
|
||||
import LinkHeader from 'http-link-header';
|
||||
import { getAccessToken, getAppToken, parseBaseURL } from 'soapbox/utils/auth';
|
||||
import { createSelector } from 'reselect';
|
||||
import { BACKEND_URL } from 'soapbox/build_config';
|
||||
import { BACKEND_URL, FE_BASE_PATH } from 'soapbox/build_config';
|
||||
import { isURL } from 'soapbox/utils/auth';
|
||||
|
||||
/**
|
||||
Parse Link headers, mostly for pagination.
|
||||
@see {@link https://www.npmjs.com/package/http-link-header}
|
||||
@param {object} response - Axios response object
|
||||
@returns {object} Link object
|
||||
*/
|
||||
export const getLinks = response => {
|
||||
const value = response.headers.link;
|
||||
if (!value) return { refs: [] };
|
||||
@@ -33,6 +44,12 @@ const getAuthBaseURL = createSelector([
|
||||
return baseURL !== window.location.origin ? baseURL : '';
|
||||
});
|
||||
|
||||
/**
|
||||
* Base client for HTTP requests.
|
||||
* @param {string} accessToken
|
||||
* @param {string} baseURL
|
||||
* @returns {object} Axios instance
|
||||
*/
|
||||
export const baseClient = (accessToken, baseURL = '') => {
|
||||
return axios.create({
|
||||
// When BACKEND_URL is set, always use it.
|
||||
@@ -45,6 +62,23 @@ export const baseClient = (accessToken, baseURL = '') => {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Dumb client for grabbing static files.
|
||||
* It uses FE_BASE_PATH and parses JSON if possible.
|
||||
* No authorization is needed.
|
||||
*/
|
||||
export const staticClient = axios.create({
|
||||
baseURL: FE_BASE_PATH,
|
||||
transformResponse: [maybeParseJSON],
|
||||
});
|
||||
|
||||
/**
|
||||
* Stateful API client.
|
||||
* Uses credentials from the Redux store if available.
|
||||
* @param {function} getState - Must return the Redux state
|
||||
* @param {string} authType - Either 'user' or 'app'
|
||||
* @returns {object} Axios instance
|
||||
*/
|
||||
export default (getState, authType = 'user') => {
|
||||
const state = getState();
|
||||
const accessToken = getToken(state, authType);
|
||||
|
||||
Reference in New Issue
Block a user