Build config: allow hardcoding BACKEND_URL into the build
This commit is contained in:
parent
b98cc6900f
commit
eea2f38f8c
2 changed files with 27 additions and 1 deletions
|
@ -4,6 +4,8 @@ import axios from 'axios';
|
||||||
import LinkHeader from 'http-link-header';
|
import LinkHeader from 'http-link-header';
|
||||||
import { getAccessToken, getAppToken, parseBaseURL } from 'soapbox/utils/auth';
|
import { getAccessToken, getAppToken, parseBaseURL } from 'soapbox/utils/auth';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
import { BACKEND_URL } from 'soapbox/build_config';
|
||||||
|
import { isURL } from 'soapbox/utils/auth';
|
||||||
|
|
||||||
export const getLinks = response => {
|
export const getLinks = response => {
|
||||||
const value = response.headers.link;
|
const value = response.headers.link;
|
||||||
|
@ -33,7 +35,8 @@ const getAuthBaseURL = createSelector([
|
||||||
|
|
||||||
export const baseClient = (accessToken, baseURL = '') => {
|
export const baseClient = (accessToken, baseURL = '') => {
|
||||||
return axios.create({
|
return axios.create({
|
||||||
baseURL,
|
// When BACKEND_URL is set, always use it.
|
||||||
|
baseURL: isURL(BACKEND_URL) ? BACKEND_URL : baseURL,
|
||||||
headers: Object.assign(accessToken ? {
|
headers: Object.assign(accessToken ? {
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
} : {}),
|
} : {}),
|
||||||
|
|
23
app/soapbox/build_config.js
Normal file
23
app/soapbox/build_config.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// @preval
|
||||||
|
/**
|
||||||
|
* Build config: configuration set at build time.
|
||||||
|
* @module soapbox/build_config
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { BACKEND_URL } = process.env;
|
||||||
|
|
||||||
|
const sanitizeURL = url => {
|
||||||
|
try {
|
||||||
|
return new URL(url).toString();
|
||||||
|
} catch {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// JSON.parse/stringify is to emulate what @preval is doing and avoid any
|
||||||
|
// inconsistent behavior in dev mode
|
||||||
|
const sanitize = obj => JSON.parse(JSON.stringify(obj));
|
||||||
|
|
||||||
|
module.exports = sanitize({
|
||||||
|
BACKEND_URL: sanitizeURL(BACKEND_URL),
|
||||||
|
});
|
Loading…
Reference in a new issue