Last active
November 18, 2019 16:58
-
-
Save autr/7321abf3f5d7ec5dec57be3fbf7f6831 to your computer and use it in GitHub Desktop.
Directus App config for multiple websites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable */ | |
(function directusConfig() { | |
/* | |
Configuration will skin a Directus App instance based on the "contains" value | |
*/ | |
const sites = [ | |
{ | |
name: 'A', | |
contains: 'admin.a.com', | |
api: 'https://directusapi.com/a/', | |
favicon: '/img/a-favicon.png', | |
logo: '/img/a-logo.png', | |
stylesheet: '/css/a.css' | |
}, | |
{ | |
name: 'B', | |
contains: 'admin.b.com', | |
api: 'https://directusapi.com/b/', | |
favicon: '/img/b-favicon.png', | |
logo: '/img/b-logo.png', | |
stylesheet: '/css/b.css' | |
}, | |
{ | |
name: 'C', | |
contains: 'admin.c.com', | |
api: 'https://directusapi.com/c/', | |
favicon: '/img/c-favicon.png', | |
logo: '/img/c-logo.png', | |
stylesheet: '/css/c.css' | |
}, | |
]; | |
let api = {}; | |
api[sites[0].api] = sites[0].name; | |
let style = null; | |
style = sites[0]; | |
sites.forEach( site => { | |
const currentPath = window.location.href.toLowerCase(); | |
if (currentPath.indexOf( site.contains ) !== -1 ) { | |
api = {}; | |
api[site.api] = site.name; | |
style = site; | |
if (site.favicon) document.querySelector("link[rel='shortcut icon']").href = site.favicon; | |
if (site.stylesheet) { | |
const head = document.head || document.getElementsByTagName('head')[0], | |
style = document.createElement('link'); | |
head.appendChild(style); | |
style.rel = 'stylesheet'; | |
style.type = 'text/css'; | |
style.href = site.stylesheet; | |
} | |
} | |
}); | |
console.log('[config.js]', 'Inferred API from URL:\n', window.location.href, '\n', api); | |
const config = { | |
// The API URLs the user can connect to using this instance of the application. | |
// Object values are used as project name in the app | |
// Don't forget to add the API environment! | |
api: api, | |
style: style, | |
// Allow the user to connect to any API by entering a URL in a text field | |
// instead of selecting from a dropdown | |
allowOtherAPI: false, | |
// Controls the way the application routes. By default, routing is done using | |
// hashes (#) to ensure the app works without any server url rewrites. | |
// | |
// If you're using the application and have the correct URL rewrites in place | |
// (everything to /index.html), you can change this to "history" to make | |
// the urls in the app a little prettier | |
routerMode: "history", // hash | history | |
// When using history mode, the application will make all the routes "pretty" | |
// by using absolute paths. If you are serving the application from a folder | |
// like /admin, this will cause the routes to be wrong (eg /collection instead | |
// of /admin/collections). To combat this, set the routerBaseUrl to the path | |
// you're serving the application from | |
routerBaseUrl: "/" | |
}; | |
window.__DirectusConfig__ = config; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment