diff --git a/app/app.js b/app/app.js index 47a01e3f..b15805f1 100644 --- a/app/app.js +++ b/app/app.js @@ -188,7 +188,7 @@ function initApp() { app.get('/doc/flight-manual', middleware.logRoute, UIController.flightManual); - app.use('/', middleware.logRoute, (req, res) => { + app.use(M.config.server.ui.basePath, middleware.logRoute, (req, res) => { res.sendFile(path.join(M.root, 'build', 'public', 'index.html')); }); } diff --git a/app/ui/components/app/App.jsx b/app/ui/components/app/App.jsx index fc399b66..3566145f 100644 --- a/app/ui/components/app/App.jsx +++ b/app/ui/components/app/App.jsx @@ -32,6 +32,7 @@ import Banner from '../general/Banner.jsx'; import { useAuth } from '../context/AuthProvider.js'; import { useApiClient } from '../context/ApiClientProvider.js'; +import uiConfig from '../../../../build/json/uiConfig.json'; export default function App(props) { const { auth, setAuth } = useAuth(); @@ -83,8 +84,16 @@ export default function App(props) { ); } + const basePath = () => { + let path = '/' + if (typeof uiConfig.basePath !== 'undefined') { + path = uiConfig.basePath.replace(/\/$/, ""); + } + return path; + }; + return ( - + { app } diff --git a/app/ui/components/app/AuthenticatedApp.jsx b/app/ui/components/app/AuthenticatedApp.jsx index a71d641b..042a0f69 100644 --- a/app/ui/components/app/AuthenticatedApp.jsx +++ b/app/ui/components/app/AuthenticatedApp.jsx @@ -32,10 +32,19 @@ import AdminConsoleHome from '../admin-console-views/admin-console-home.jsx'; import About from '../general/About.jsx'; import NotFound from '../shared-views/NotFound.jsx'; +import uiConfig from '../../../../build/json/uiConfig.json'; + export default function AuthenticatedApp(props) { + const basePath = () => { + let path = '/' + if (typeof uiConfig.basePath !== 'undefined') { + path = uiConfig.basePath.replace(/\/$/, ""); + } + return path; + }; return ( - }/> + }/> diff --git a/app/ui/html/index_template.html b/app/ui/html/index_template.html index ed6bc442..f594068a 100644 --- a/app/ui/html/index_template.html +++ b/app/ui/html/index_template.html @@ -5,17 +5,17 @@ - + Login | Model-Based Engineering Environment - + - - - + + + @@ -28,11 +28,11 @@ - - - - - + + + + + diff --git a/config/default.cfg b/config/default.cfg index 42708117..b50bc764 100644 --- a/config/default.cfg +++ b/config/default.cfg @@ -102,6 +102,7 @@ "ui": { "enabled": true, "mode": "production", + "basePath": "/mcf", "loginModal": { "on": false, "message": "This is where your login modal message gets placed.", diff --git a/config/example.cfg b/config/example.cfg index 8a4a2166..74d88776 100644 --- a/config/example.cfg +++ b/config/example.cfg @@ -351,6 +351,8 @@ "enabled": true, // Defining if the UI is in production or development mode. "mode": "production", + // Defining the base path for the UI + "basePath": "/", // The UI can display a login modal warning statement. The following parameters // are used to set up the modal message. // REQUIRED if enabled is true diff --git a/package.json b/package.json index 5f398ccd..aa33d693 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "mbee", - "version": "2.0.1", + "version": "2.1.0", "build": "NO_BUILD_NUMBER", "description": "Model-Based Engineering Environment", "main": "mbee.js", - "repository": "https://github.com/lmco/mbee.git", + "repository": "https://github.com/open-mbee/mcf.git", "author": "Lockheed Martin", "license": "Apache-2.0", "private": true, @@ -64,6 +64,7 @@ "gulp-markdown": "^5.0.0", "gulp-minify": "^3.1.0", "gulp-sass": "^4.0.1", + "html-replace-webpack-plugin": "^2.6.0", "html-webpack-plugin": "^4.3.0", "jquery": "^3.3.1", "jquery-ui-dist": "^1.12.1", diff --git a/scripts/build.js b/scripts/build.js index f9d22a07..61327926 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -41,11 +41,20 @@ const markdown = require('gulp-markdown'); const rename = require('gulp-rename'); const webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); +const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin'); // MBEE modules const validators = M.require('lib.validators'); const utils = M.require('lib.utils'); +const basePath = () => { + let bpath = ''; + if (typeof M.config.server.ui.basePath !== 'undefined') { + bpath = M.config.server.ui.basePath.replace(/\/$/, ''); + } + return bpath; +}; + /** * @description Builds the MBEE static assets by: * - Copying dependencies to their final location @@ -201,7 +210,7 @@ function build(_args) { output: { path: path.join(M.root, 'build', 'public', 'js'), filename: 'index_bundle.js', - publicPath: '/js/' + publicPath: `${basePath()}/js/` }, devServer: { historyApiFallback: true @@ -223,7 +232,14 @@ function build(_args) { new HtmlWebpackPlugin({ template: path.join(M.root, 'app', 'ui', 'html', 'index_template.html'), filename: path.join(M.root, 'build', 'public', 'index.html') - }) + }), + new HtmlReplaceWebpackPlugin([ + { + pattern: '@@basePath', + replacement: `${basePath()}/` + } + + ]) ] }, (err, stats) => { if (err || stats.hasErrors()) { @@ -241,8 +257,9 @@ function build(_args) { .then(() => { M.log.info('Build Complete.'); }) - .catch(() => { + .catch((e) => { M.log.warn('React build FAILED'); + M.log.debug(e.stack); M.log.info('Build Complete.'); }); }