Build config: allow hardcoding BACKEND_URL into the build

merge-requests/694/head
Alex Gleason 2021-08-26 20:39:47 -07:00
rodzic b98cc6900f
commit eea2f38f8c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 27 dodań i 1 usunięć

Wyświetl plik

@ -4,6 +4,8 @@ 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 { isURL } from 'soapbox/utils/auth';
export const getLinks = response => {
const value = response.headers.link;
@ -33,7 +35,8 @@ const getAuthBaseURL = createSelector([
export const baseClient = (accessToken, baseURL = '') => {
return axios.create({
baseURL,
// When BACKEND_URL is set, always use it.
baseURL: isURL(BACKEND_URL) ? BACKEND_URL : baseURL,
headers: Object.assign(accessToken ? {
'Authorization': `Bearer ${accessToken}`,
} : {}),

Wyświetl plik

@ -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),
});