Pass base url to SDK only if provided

This commit is contained in:
Hannu Lyytikainen 2018-11-28 10:03:49 +02:00
parent 08e23c7c83
commit 7177cb37c7
3 changed files with 8 additions and 3 deletions

View file

@ -7,6 +7,7 @@ const unsafeEval = "'unsafe-eval'";
const data = 'data:';
const blob = 'blob:';
const devImagesMaybe = dev ? ['*.localhost:8000'] : [];
const baseUrl = process.env.REACT_APP_SHARETRIBE_SDK_BASE_URL || 'https://flex-api.sharetribe.com';
// Default CSP whitelist.
//
@ -18,7 +19,7 @@ const defaultDirectives = {
childSrc: [blob],
connectSrc: [
self,
process.env.REACT_APP_SHARETRIBE_SDK_BASE_URL,
baseUrl,
'maps.googleapis.com',
'*.tiles.mapbox.com',
'api.mapbox.com',

View file

@ -167,10 +167,11 @@ app.get('*', (req, res) => {
secure: USING_SSL,
});
const baseUrl = BASE_URL ? { baseUrl: BASE_URL } : {};
const sdk = sharetribeSdk.createInstance({
transitVerbose: TRANSIT_VERBOSE,
clientId: CLIENT_ID,
baseUrl: BASE_URL,
httpAgent: httpAgent,
httpsAgent: httpsAgent,
tokenStore,
@ -182,6 +183,7 @@ app.get('*', (req, res) => {
reader: v => new Decimal(v.value),
},
],
...baseUrl,
});
// Until we have a better plan for caching dynamic content and we

View file

@ -77,13 +77,14 @@ if (typeof window !== 'undefined') {
// set up logger with Sentry DSN client key and environment
log.setup();
const baseUrl = config.sdk.baseUrl ? { baseUrl: config.sdk.baseUrl } : {};
// eslint-disable-next-line no-underscore-dangle
const preloadedState = window.__PRELOADED_STATE__ || '{}';
const initialState = JSON.parse(preloadedState, sdkTypes.reviver);
const sdk = createInstance({
transitVerbose: config.sdk.transitVerbose,
clientId: config.sdk.clientId,
baseUrl: config.sdk.baseUrl,
secure: config.usingSSL,
typeHandlers: [
{
@ -93,6 +94,7 @@ if (typeof window !== 'undefined') {
reader: v => new Decimal(v.value),
},
],
...baseUrl,
});
const analyticsHandlers = setupAnalyticsHandlers();
const store = configureStore(initialState, sdk, analyticsHandlers);