Commit 1addaeaf authored by Robert Knight's avatar Robert Knight

Call `fetchConfig` to fetch Hypothesis client settings

This causes the client to fetch settings from an ancestor frame on
startup if necessary.
parent b2df9cd7
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
const addAnalytics = require('./ga'); const addAnalytics = require('./ga');
const disableOpenerForExternalLinks = require('./util/disable-opener-for-external-links'); const disableOpenerForExternalLinks = require('./util/disable-opener-for-external-links');
const getApiUrl = require('./get-api-url'); const { fetchConfig } = require('./util/fetch-config');
const serviceConfig = require('./service-config'); const serviceConfig = require('./service-config');
const crossOriginRPC = require('./cross-origin-rpc.js'); const crossOriginRPC = require('./cross-origin-rpc.js');
require('../shared/polyfills'); require('../shared/polyfills');
...@@ -113,19 +113,6 @@ function setupHttp($http, streamer) { ...@@ -113,19 +113,6 @@ function setupHttp($http, streamer) {
$http.defaults.headers.common['X-Client-Id'] = streamer.clientId; $http.defaults.headers.common['X-Client-Id'] = streamer.clientId;
} }
/**
* Merge settings rendered into sidebar app HTML page with
* settings provided by the embedder of Hypothesis.
*/
function fetchConfig(appConfig) {
const hostPageConfig = require('./host-config');
const mergedConfig = Object.assign({}, appConfig, hostPageConfig(window));
mergedConfig.apiUrl = getApiUrl(mergedConfig);
return Promise.resolve(mergedConfig);
}
function startAngularApp(config) { function startAngularApp(config) {
angular.module('h', [ angular.module('h', [
// Angular addons which export the Angular module name // Angular addons which export the Angular module name
...@@ -257,5 +244,8 @@ function startAngularApp(config) { ...@@ -257,5 +244,8 @@ function startAngularApp(config) {
fetchConfig(appConfig).then(config => { fetchConfig(appConfig).then(config => {
startAngularApp(config); startAngularApp(config);
}).catch(err => { }).catch(err => {
console.error(err); // Report error. This will be the only notice that the user gets because the
// sidebar does not currently appear at all if the Angular app fails to
// start.
console.error('Failed to start Hypothesis client: ', err);
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment