Skip to content

Commit

Permalink
Introduce clientBaseUrl and languageBaseUrl options to deprecate asse…
Browse files Browse the repository at this point in the history
…tsUrl. Fixes #576
  • Loading branch information
cristiandouce committed Sep 12, 2016
1 parent bbced66 commit 4f37f58
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ var options = {

#### Other options

- **assetsUrl {String}**: Will be used as the assets base url. Defaults to Auth0's the CDN url when `domain` has the format `*.auth0.com`. Otherwise, it defaults to `domain`.
- **clientBaseUrl {String}**: Overrides client settings base url. By default it uses Auth0's CDN url when `domain` has the format `*.auth0.com`. Otherwise, it uses the provided `domain`.
- **languageBaseUrl {String}**: Overrides the language source url for Auth0's provided translations. By default it uses to Auth0's CDN url `https://cdn.auth0.com`.

#### Language Dictionary Specification

Expand Down
4 changes: 2 additions & 2 deletions src/core/client/settings.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { load } from '../../utils/cdn_utils';

export function fetchClientSettings(clientID, assetsUrl, cb) {
export function fetchClientSettings(clientID, clientBaseUrl, cb) {
load({
method: "setClient",
url: `${assetsUrl}/client/${clientID}.js?t${+new Date()}`,
url: `${clientBaseUrl}/client/${clientID}.js?t${+new Date()}`,
check: o => o && o.id === clientID,
cb: cb
});
Expand Down
29 changes: 25 additions & 4 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const {

export function setup(id, clientID, domain, options, hookRunner, emitEventFn) {
let m = init(id, Immutable.fromJS({
assetsUrl: extractAssetsUrlOption(options, domain),
clientBaseUrl: extractClientBaseUrlOption(options, domain),
languageBaseUrl: extractLanguageBaseUrlOption(options, domain),
auth: extractAuthOptions(options),
clientID: clientID,
domain: domain,
Expand All @@ -48,10 +49,13 @@ export function domain(m) {
return get(m, "domain");
}

export function assetsUrl(m) {
return get(m, "assetsUrl");
export function clientBaseUrl(m) {
return get(m, "clientBaseUrl");
}

export function languageBaseUrl(m) {
return get(m, "languageBaseUrl");
}
export function setSubmitting(m, value, error = "") {
m = tset(m, "submitting", value);
m = clearGlobalSuccess(m);
Expand Down Expand Up @@ -201,7 +205,11 @@ export function withAuthOptions(m, opts) {
.toJS();
}

function extractAssetsUrlOption(opts, domain) {
function extractClientBaseUrlOption(opts, domain) {
if (opts.clientBaseUrl && typeof opts.clientBaseUrl === "string") {
return opts.clientBaseUrl;
}

if (opts.assetsUrl && typeof opts.assetsUrl === "string") {
return opts.assetsUrl;
}
Expand All @@ -220,6 +228,19 @@ function extractAssetsUrlOption(opts, domain) {
}
}

function extractLanguageBaseUrlOption(opts, domain) {
if (opts.languageBaseUrl && typeof opts.languageBaseUrl === "string") {
return opts.languageBaseUrl;
}

if (opts.assetsUrl && typeof opts.assetsUrl === "string") {
return opts.assetsUrl;
}

return "https://cdn.auth0.com"
}


export function render(m) {
return tset(m, "render", true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/remote_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import sync, { isSuccess } from '../sync';

export function syncRemoteData(m) {
m = sync(m, "client", {
syncFn: (m, cb) => fetchClientSettings(l.clientID(m), l.assetsUrl(m), cb),
syncFn: (m, cb) => fetchClientSettings(l.clientID(m), l.clientBaseUrl(m), cb),
successFn: syncClientSettingsSuccess
});

Expand Down
2 changes: 1 addition & 1 deletion src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function initI18n(m) {
function syncLang(m, language, cb) {
load({
method: "registerLanguageDictionary",
url: `${l.assetsUrl(m)}/js/lock/${__VERSION__}/${language}.js`,
url: `${l.languageBaseUrl(m)}/js/lock/${__VERSION__}/${language}.js`,
check: str => str && str === language,
cb: (err, _, dictionary) => {
cb(err, dictionary);
Expand Down
2 changes: 1 addition & 1 deletion support/design/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ WebAPI.prototype.parseHash = function(lockID, ...args) {
return null;
}

ClientSettings.fetchClientSettings = function(clientID, assetsUrl, cb) {
ClientSettings.fetchClientSettings = function(clientID, clientBaseUrl, cb) {
// TODO: we should have propper settings for every configuration.
const settings = {
strategies: [
Expand Down

0 comments on commit 4f37f58

Please sign in to comment.