From b991b1af2665d6ec820060f4f861ce2dd0ce2196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20Zen?= Date: Fri, 15 Jul 2016 16:16:33 -0300 Subject: [PATCH] basepath config as singleton --- src/actions/config.js | 3 ++- src/routing/basePath.js | 10 ++++++++++ src/routing/history.js | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/routing/basePath.js diff --git a/src/actions/config.js b/src/actions/config.js index c0148f3e..14c51e34 100644 --- a/src/actions/config.js +++ b/src/actions/config.js @@ -2,6 +2,7 @@ import yaml from 'js-yaml'; import { currentBackend } from '../backends/backend'; import { authenticate } from '../actions/auth'; import * as MediaProxy from '../valueObjects/MediaProxy'; +import basePath from '../routing/basePath'; export const CONFIG_REQUEST = 'CONFIG_REQUEST'; export const CONFIG_SUCCESS = 'CONFIG_SUCCESS'; @@ -43,7 +44,7 @@ export function loadConfig(config) { return (dispatch, getState) => { dispatch(configLoading()); - fetch('/config.yml').then((response) => { + fetch(`${basePath}/config.yml`).then((response) => { if (response.status !== 200) { throw `Failed to load config.yml (${response.status})`; } diff --git a/src/routing/basePath.js b/src/routing/basePath.js new file mode 100644 index 00000000..d00abe17 --- /dev/null +++ b/src/routing/basePath.js @@ -0,0 +1,10 @@ +const base = document.querySelector('base'); + +let basePath; +if (base && base.href) { + basePath = base.attributes.getNamedItem('href').value; +} else { + basePath = ''; +} + +export default basePath; diff --git a/src/routing/history.js b/src/routing/history.js index 12a7b087..4825aba1 100644 --- a/src/routing/history.js +++ b/src/routing/history.js @@ -1,10 +1,10 @@ import { createHistory } from 'history'; import { useRouterHistory } from 'react-router'; import { syncHistoryWithStore } from 'react-router-redux'; +import basePath from './basePath'; -const base = document.querySelector('base'); let history = useRouterHistory(createHistory)({ - basename: base && base.href || '' + basename: basePath }); const syncHistory = (store) => {