Nuke root url

This commit is contained in:
dannyrb 2019-04-29 14:42:29 -04:00
parent 1d7ddd5bf5
commit 319af9bde3
4 changed files with 33 additions and 13 deletions

View File

@ -1,6 +1,8 @@
window.config = {
// default: '/'
routerBasename: '/',
rootUrl: 'http://localhost:5000',
// default: ''
relativeWebWorkerScriptsPath: '',
servers: {
dicomWeb: [
{

View File

@ -1,6 +1,8 @@
window.config = {
// default: '/'
routerBasename: '/demo',
rootUrl: '/demo',
// default: '/'
relativeWebWorkerScriptsPath: '',
servers: {
dicomWeb: [
{

View File

@ -192,16 +192,22 @@ function handleOIDC(oidc) {
return userManager
}
function handleWebWorkerInit(basename) {
/**
*
* @param {String} baseDirectory
* @param {String} webWorkScriptsPath
*/
function handleWebWorkerInit(baseDirectory, webWorkScriptsPath) {
const scriptsPath = `${baseDirectory}/${webWorkScriptsPath}`
const config = {
maxWebWorkers: Math.max(navigator.hardwareConcurrency - 1, 1),
startWebWorkersOnDemand: true,
webWorkerPath: basename + '/cornerstoneWADOImageLoaderWebWorker.min.js',
webWorkerPath: `${scriptsPath}/cornerstoneWADOImageLoaderWebWorker.min.js`,
taskConfiguration: {
decodeTask: {
loadCodecsOnStartup: true,
initializeCodecsOnStartup: false,
codecsPath: basename + '/cornerstoneWADOImageLoaderCodecs.min.js',
codecsPath: `${scriptsPath}/cornerstoneWADOImageLoaderCodecs.min.js`,
usePDFJS: false,
strict: false,
},
@ -213,13 +219,14 @@ function handleWebWorkerInit(basename) {
/**
* Set or update the HTML Base tag present on the document
* to point to the provided ROOT Url.
*
* @param rootUrl
*/
function updateBaseTag(rootUrl) {
function updateBaseTag(baseDirectory = '') {
const bases = document.getElementsByTagName('base')
let baseHref = rootUrl
let baseHref = `${window.location.scheme}${
window.location.host
}${baseDirectory}`
baseHref += baseHref.endsWith('/') ? '' : '/'
if (bases.length > 1) {
@ -233,10 +240,11 @@ function updateBaseTag(rootUrl) {
class App extends Component {
static propTypes = {
routerBasename: PropTypes.string,
relativeWebWorkerScriptsPath: PropTypes.string,
//
servers: PropTypes.object,
oidc: PropTypes.array,
routerBasename: PropTypes.string,
rootUrl: PropTypes.string,
userManager: PropTypes.object,
location: PropTypes.object,
}
@ -250,8 +258,11 @@ class App extends Component {
this.userManager = handleOIDC(this.props.oidc)
handleServers(this.props.servers)
handleWebWorkerInit(this.props.rootUrl)
updateBaseTag(this.props.rootUrl)
handleWebWorkerInit(
this.props.routerBasename,
this.props.relativeWebWorkerScriptsPath
)
updateBaseTag(this.props.routerBasename)
}
render() {

View File

@ -8,7 +8,12 @@ import ReactDOM from 'react-dom'
export { App }
const applicationProps = window.config
window.config = window.config || {}
const applicationDefaults = {
routerBasename: '/',
relativeWebWorkerScriptsPath: '',
}
const applicationProps = Object.assign({}, applicationDefaults, window.config)
const app = React.createElement(App, applicationProps, null)
ReactDOM.render(app, document.getElementById('root'))