diff --git a/app/react/src/server/index.html.js b/app/react/src/server/index.html.js index fa7b791d8413..3499e26c5b83 100644 --- a/app/react/src/server/index.html.js +++ b/app/react/src/server/index.html.js @@ -28,7 +28,7 @@ const managerUrlsFromAssets = assets => { }; export default function(data) { - const { assets, publicPath } = data; + const { assets, publicPath, bodyScript } = data; const managerUrls = managerUrlsFromAssets(assets); @@ -73,6 +73,7 @@ export default function(data) {
+ ${bodyScript} diff --git a/app/react/src/server/middleware.js b/app/react/src/server/middleware.js index e2ca8d2ace87..c54c792b214a 100644 --- a/app/react/src/server/middleware.js +++ b/app/react/src/server/middleware.js @@ -6,7 +6,7 @@ import getBaseConfig from './config/webpack.config'; import loadConfig from './config'; import getIndexHtml from './index.html'; import getIframeHtml from './iframe.html'; -import { getHeadHtml, getMiddleware } from './utils'; +import { getHeadHtml, getBodyScript, getMiddleware } from './utils'; export default function(configDir) { // Build the webpack configuration using the `getBaseConfig` @@ -36,7 +36,8 @@ export default function(configDir) { middlewareFn(router); router.get('/', (req, res) => { - res.send(getIndexHtml({ publicPath })); + const bodyScript = getBodyScript(configDir) + res.send(getIndexHtml({ publicPath, bodyScript })); }); router.get('/iframe.html', (req, res) => { diff --git a/app/react/src/server/utils.js b/app/react/src/server/utils.js index 19811869d4fd..1dff08dd1622 100644 --- a/app/react/src/server/utils.js +++ b/app/react/src/server/utils.js @@ -15,6 +15,17 @@ export function getHeadHtml(configDirPath) { return headHtml; } +export function getBodyScript(configDirPath) { + const scriptPath = path.resolve(configDirPath, 'bodyscript.html'); + let scriptHtml = ''; + if (fs.existsSync(scriptPath)) { + scriptHtml = fs.readFileSync(scriptPath, 'utf8'); + } + + return scriptHtml; +} + + export function getEnvConfig(program, configEnv) { Object.keys(configEnv).forEach(fieldName => { const envVarName = configEnv[fieldName];