mirror of
https://github.com/wassname/talk.git
synced 2026-07-04 06:11:13 +08:00
abstracted config to service
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
// This is always loaded in the body of the page, meaning that the dom element
|
||||
// for this data blob is always loaded when we render this piece.
|
||||
const CONFIG_ELEMENT = document.querySelector('#data');
|
||||
|
||||
// Parse the configuration from that element if it exists, otherwise, an empty
|
||||
// object.
|
||||
const CONFIG = CONFIG_ELEMENT ? JSON.parse(CONFIG_ELEMENT.textContent) : {};
|
||||
|
||||
// Export the expected fields.
|
||||
export const LIVE_URI = CONFIG.LIVE_URI;
|
||||
export const STATIC_URL = CONFIG.STATIC_URL;
|
||||
@@ -1,6 +1,9 @@
|
||||
/* global __webpack_public_path__ */ // eslint-disable-line no-unused-vars
|
||||
|
||||
import { STATIC_URL } from 'coral-framework/constants/config';
|
||||
import { getStaticConfiguration } from 'coral-framework/services/staticConfiguration';
|
||||
|
||||
// Load the static url from the static configuration.
|
||||
const { STATIC_URL } = getStaticConfiguration();
|
||||
|
||||
// Update the static url for the imported public path so dynamically imported
|
||||
// chunks will use the correct path as defined by the process.env.STATIC_URL
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
import { LIVE_URI } from 'coral-framework/constants/config';
|
||||
import { getStaticConfiguration } from 'coral-framework/services/staticConfiguration';
|
||||
import { createStore } from './store';
|
||||
import { createClient, apolloErrorReporter } from './client';
|
||||
import pym from './pym';
|
||||
@@ -83,8 +83,8 @@ export async function createContext({
|
||||
token,
|
||||
});
|
||||
|
||||
let liveUri = null;
|
||||
if (LIVE_URI == null) {
|
||||
let { LIVE_URI: liveUri } = getStaticConfiguration();
|
||||
if (liveUri == null) {
|
||||
// The protocol must match the origin protocol, secure/insecure.
|
||||
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* getStaticConfiguration will return a singleton of the static configuration
|
||||
* object provided via a JSON DOM element.
|
||||
*/
|
||||
let staticConfiguration = null;
|
||||
export const getStaticConfiguration = () => {
|
||||
if (staticConfiguration != null) {
|
||||
return staticConfiguration;
|
||||
}
|
||||
|
||||
const configElement = document.querySelector('#data');
|
||||
|
||||
staticConfiguration = JSON.parse(
|
||||
configElement ? configElement.textContent : '{}'
|
||||
);
|
||||
|
||||
return staticConfiguration;
|
||||
};
|
||||
Reference in New Issue
Block a user