UNPKG

@infomaker/imid-gui

Version:

Utility lib to simplify implementation of IMID related views, such aas 'sign in', 'Unauthorized', 'Session expired' etc.

38 lines (31 loc) 1.15 kB
const fs = require('fs') const path = require('path') // Todo, add some validation of settings object // Add error handling const getHTMLForUnitSwitch = settings => { const htmlString = getHTMLString(path.resolve(__dirname, 'unitswitcher.html')) return injectSettingsObject(settings, htmlString) } const getHTMLForUnauthorized = settings => { const htmlString = getHTMLString(path.resolve(__dirname, 'unauthorized.html')) return injectSettingsObject(settings, htmlString) } const getHTMLForLoginExpired = settings => { const htmlString = getHTMLString(path.resolve(__dirname, 'loginexpired.html')) return injectSettingsObject(settings, htmlString) } const getHTMLString = filePath => { const htmlFileContent = fs.readFileSync(filePath, 'UTF-8') return htmlFileContent.toString() } const injectSettingsObject = (settings, htmlString) => { return htmlString.replace( '<script type="replace-before-render"></script>', `<script>window.settings = ${JSON.stringify(settings)}</script>` ) } module.exports = { getHTMLForUnitSwitch, getHTMLForUnauthorized, getHTMLForLoginExpired, }