Skip to content

Commit

Permalink
add base url at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalesi committed Oct 23, 2023
1 parent 2225b49 commit eb1f942
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 84 deletions.
26 changes: 14 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nexus Fusion</title>
<!--app-head-->
</head>

<body>
<div id="root"><!--app-html--></div>
<!--app-state-->
<script type="module" src="/src/index.tsx"></script>
<!--scripts-->
</body>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nexus Fusion</title>
<!--app-head-->
</head>

<body>
<div id="root"><!--app-html--></div>
<!--app-state-->
<script type="module" src="/src/index.tsx"></script>
<!--scripts-->
</body>

</html>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
"util": "^0.12.5",
"vite": "^4.4.9",
"vite-compatible-readable-stream": "^3.6.1",
"vite-plugin-dynamic-base": "^1.0.0",
"vite-plugin-dynamic-import": "^1.5.0",
"vitest": "^0.34.5"
},
Expand Down
5 changes: 2 additions & 3 deletions server/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ LIMIT 1000`;
const DEFAULT_SEARCH_CONFIG_PROJECT = 'webapps/nexus-web';
const DEFAULT_SERVICE_ACCOUNTS_REALM = 'serviceaccounts';
const rawBase = process.env.BASE_PATH || '';
// to develop plugins locally, change PLUGINS_PATH to '/public/plugins'
const pluginsManifestPath = process.env.PLUGINS_MANIFEST_PATH || '/plugins';
const pluginsManifestPath = process.env.PLUGINS_MANIFEST_PATH || `dist/plugins`;

// configure instance logo
const layoutSettings = {
Expand All @@ -149,7 +148,7 @@ const searchSettings = {
const dataModelsLocation = process.env.DATA_MODELS || '';

const subAppsManifestPath =
process.env.SUB_APPS_MANIFEST_PATH || '/public/sub-apps';
process.env.SUB_APPS_MANIFEST_PATH || '/dist/sub-apps';

const base = rawBase.replace(/\/$/, '');

Expand Down
4 changes: 3 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ async function transformer(html: string, req: Request) {
.replace(
'<!--app-head-->',
`
<script>
window.__BASE__ = '${base}'
</script>
<base href="${base}" />
${helmet.title.toString()}
${helmet.meta.toString()}
Expand All @@ -100,7 +103,6 @@ async function transformer(html: string, req: Request) {
.replace(
'<!--app-state-->',
`<script>
window.__BASE__ = '${base}';
// WARNING: See the following for security issues around embedding JSON in HTML:
// http://redux.js.org/recipes/ServerRendering.html#security-considerations
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(
Expand Down
1 change: 0 additions & 1 deletion src/shared/hooks/usePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default function usePlugins() {
})
)
.catch(error => {
console.log('@@error', error);
setManifest({
error,
loading: false,
Expand Down
61 changes: 0 additions & 61 deletions src/shared/lib.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,67 +52,6 @@ $fusion-heading-4-size: 16px;
$fusion-heading-5-size: 14px;
$fusion-body-small: 10px;

@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-Italic.ttf') format('truetype');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-Bold.ttf') format('truetype');
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-BoldItalic.ttf') format('truetype');
font-weight: bold;
font-style: italic;
}
@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-SemiBold.ttf') format('truetype');
font-weight: 600;
font-style: normal;
}
@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-SemiBoldItalic.ttf') format('truetype');
font-weight: 600;
font-style: italic;
}
@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-Light.ttf') format('truetype');
font-weight: 300;
font-style: normal;
}
@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-LightItalic.ttf') format('truetype');
font-weight: 300;
font-style: italic;
}
@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-ExtraLight.ttf') format('truetype');
font-weight: 100;
font-style: normal;
}
@font-face {
font-family: 'Titillium Web';
src: url('./fonts/TitilliumWeb-ExtraLightItalic.ttf') format('truetype');
font-weight: 100;
font-style: italic;
}

// Fusion Variables
$header-background-color: fade($fusion-component-background-color, 50%);
$box-shadow-color: #abbac9;
Expand Down
14 changes: 10 additions & 4 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@
import { defineConfig } from 'vite';
import { fileURLToPath } from 'url';

import { dynamicBase } from 'vite-plugin-dynamic-base';
import { execSync } from "child_process";
import react from '@vitejs/plugin-react';
import svgrPlugin from 'vite-plugin-svgr';
import tsconfigPaths from 'vite-tsconfig-paths';
import commonjs from 'vite-plugin-commonjs';
import viteCompression from 'vite-plugin-compression';

import 'vite-compatible-readable-stream';
import { execSync } from "child_process"

export default defineConfig(() => {
const commitHash = execSync('git rev-parse HEAD').toString().trimEnd();
const version = execSync('git describe --tags').toString().trimEnd();

return ({
base: "/__BASE__/",
plugins: [
react(),
tsconfigPaths(),
svgrPlugin(),
commonjs(),
viteCompression(),
dynamicBase({
publicPath: 'window.__BASE__',
transformIndexHtml: true,
})
],
resolve: {
alias: {
Expand Down Expand Up @@ -66,9 +71,10 @@ export default defineConfig(() => {
build: {
minify: true,
cssMinify: true,
manifest: false,
manifest: true,
emptyOutDir: false,
outDir: 'dist',
assetsDir: 'public',
commonjsOptions: {
transformMixedEsModules: true
},
Expand All @@ -81,7 +87,7 @@ export default defineConfig(() => {
codemirror: ["codemirror", "react-codemirror2"]
}
}
}
},
},
assetsInclude: ['**/*.jpg', '**/*.jpeg', '**/*.mp4', '**/*.png', '**/*.svg']
})
Expand Down
99 changes: 97 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3856,6 +3856,85 @@
"@svgr/plugin-svgo" "^4.3.1"
loader-utils "^1.2.3"

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.94.tgz#2fe8e513433cd5d5c987952e38ca06e6226de0f3"
integrity sha512-KNuE6opIy/wAXiGUWLhGWhCG3wA/AdjG6eYkv6dstrAURLaQMAoD8vDfVm8pxS8FA8Kx+0Z4QiDNPqk5aKIsqg==

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.94.tgz#6b626013657e18eaf1e795370eac70e86dc7d300"
integrity sha512-HypemhyehQrLqXwfJv5ronD4BMAXdgMCP4Ei7rt3B6Ftmt9axwGvdwGiXxsYR9h1ncyxoVxN+coGxbNIhKhahw==

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.94.tgz#300483c9e9a3a4084d8264f59daee19102e1084b"
integrity sha512-KzKN54c7Y6X1db+bBVSXG4+bXmAPvXtDWk+TgwNJH4yYliOrnP/RKkHA5QZ9VFSnqJF06/sAO4kYBiL/aVQDBQ==

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.94.tgz#ac099db32d60e161c11bf01a9496ea0ada347247"
integrity sha512-iAcR8Ho0Uck/SLSrgYfXkpcGOXuN5waMZO7GlL/52QODr7GJtOfZ0H1MCZLbIFkPJp/iXoJpYgym4d/qSd477Q==

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.94.tgz#e555791abf27d74831dc3581327662f65e2b62f2"
integrity sha512-VCHL1Mb9ENHx+sAeubSSg481MUeP9/PYzPPy9tfswunj/w35M+vEWflwK2dzQL9kUTFD3zcFTpAgsKnj6aX24w==

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.94.tgz#8d7d4104ba29ce0d7871472c69a7616db2908850"
integrity sha512-gjq7U6clhJi0Oel2a4gwR4MbSu+THQ2hmBNVCOSA3JjPZWZTkJXaJDpnh/r7PJxKBwUDlo0VPlwiwjepAQR2Rw==

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.94.tgz#d7180fcff29339b7a2011670a1e1697a2075d13d"
integrity sha512-rSylruWyeol2ujZDHmwiovupMR5ukMXivlA7DDxmQ1dFUV9HuiPknQrU5rEbI3V2V3V5RkpbEKjnADen7AeMPQ==

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.94.tgz#1ddab334f90ba40fb2b7768476fb64f4e8f1d759"
integrity sha512-OenDUr5MQkz506ebVQq6ezoZ3GZ26nchgf5mPnwab4gx2TEiyR9zn7MdX5LWskTmOK3+FszPbGK0B5oLK6Y5yw==

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.94.tgz#e254b4ab6514cf0ebd89781c7bf348484d006b8b"
integrity sha512-mi6NcmtJKnaiHAxLtVz+WzunscsEwPdA0j15DuiYVx06Xo+MdRLJj4eVBgVLwGD1AI3IqKs4MVVx2cD7n0h5mg==

"@swc/[email protected]":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.94.tgz#dc193537ccd87f40552e099038f543e0756f74de"
integrity sha512-Ba0ZLcGMnqPWWF9Xa+rWhhnkpvE7XoQegMP/VCF2JIHb2ieGBC8jChO6nKRFKZjib/3wghGzxakyDQx3LDhDug==

"@swc/core@^1.3.61":
version "1.3.94"
resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.3.94.tgz#3719cbec7d05e8228fd5b5c7e0dec65ecf2d0422"
integrity sha512-jTHn8UJOGgERKZLy8euEixVAzC/w/rUSuMlM3e7hxgap/TC595hSkuQwtkpL238dsuEPveD44GMy2A5UBtSvjg==
dependencies:
"@swc/counter" "^0.1.1"
"@swc/types" "^0.1.5"
optionalDependencies:
"@swc/core-darwin-arm64" "1.3.94"
"@swc/core-darwin-x64" "1.3.94"
"@swc/core-linux-arm-gnueabihf" "1.3.94"
"@swc/core-linux-arm64-gnu" "1.3.94"
"@swc/core-linux-arm64-musl" "1.3.94"
"@swc/core-linux-x64-gnu" "1.3.94"
"@swc/core-linux-x64-musl" "1.3.94"
"@swc/core-win32-arm64-msvc" "1.3.94"
"@swc/core-win32-ia32-msvc" "1.3.94"
"@swc/core-win32-x64-msvc" "1.3.94"

"@swc/counter@^0.1.1":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@swc/counter/-/counter-0.1.2.tgz#bf06d0770e47c6f1102270b744e17b934586985e"
integrity sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw==

"@swc/types@^0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.5.tgz#043b731d4f56a79b4897a3de1af35e75d56bc63a"
integrity sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw==

"@testing-library/cypress@^8.0.3":
version "8.0.7"
resolved "https://registry.yarnpkg.com/@testing-library/cypress/-/cypress-8.0.7.tgz#18315eba3cf8852808afadf122e4858406384015"
Expand Down Expand Up @@ -7538,7 +7617,7 @@ css-select@^2.0.0:
domutils "^1.7.0"
nth-check "^1.0.2"

css-select@^4.1.3:
css-select@^4.1.3, css-select@^4.2.1:
version "4.3.0"
resolved "https://registry.yarnpkg.com/css-select/-/css-select-4.3.0.tgz#db7129b2846662fd8628cfc496abb2b59e41529b"
integrity sha512-wPpOYtnsVontu2mODhA19JrqWxNsfdatRKd64kmpRbQgh1KtItko5sTnEpPdpSaJszTOhEMlF/RPz28qj4HqhQ==
Expand Down Expand Up @@ -10386,7 +10465,7 @@ hastscript@^5.0.0:
property-information "^5.0.0"
space-separated-tokens "^1.0.0"

he@^1.2.0:
he@1.2.0, he@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
Expand Down Expand Up @@ -13191,6 +13270,14 @@ node-fetch@^2.0.0, node-fetch@^2.6.0, node-fetch@^2.6.12, node-fetch@^2.6.7:
dependencies:
whatwg-url "^5.0.0"

node-html-parser@^5.3.3:
version "5.4.2"
resolved "https://registry.yarnpkg.com/node-html-parser/-/node-html-parser-5.4.2.tgz#93e004038c17af80226c942336990a0eaed8136a"
integrity sha512-RaBPP3+51hPne/OolXxcz89iYvQvKOydaqoePpOgXcrOKZhjVIzmpKZz+Hd/RBO2/zN2q6CNJhQzucVz+u3Jyw==
dependencies:
css-select "^4.2.1"
he "1.2.0"

node-libs-browser@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/node-libs-browser/-/node-libs-browser-2.2.1.tgz#b64f513d18338625f90346d27b0d235e631f6425"
Expand Down Expand Up @@ -18451,6 +18538,14 @@ vite-plugin-compression@^0.5.1:
debug "^4.3.3"
fs-extra "^10.0.0"

vite-plugin-dynamic-base@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/vite-plugin-dynamic-base/-/vite-plugin-dynamic-base-1.0.0.tgz#248714f7150f12d9c69bfe244a0d91b2ccc33d3c"
integrity sha512-BSfE7I2HCOk6Jmlxaq0hw3FWkBg8g7kGuwisj2tlDSRYPEQzJliKEvPkkvHZgd7jNJLwSMzEES1oWzc1BR+CSw==
dependencies:
"@swc/core" "^1.3.61"
node-html-parser "^5.3.3"

vite-plugin-dynamic-import@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/vite-plugin-dynamic-import/-/vite-plugin-dynamic-import-1.5.0.tgz#a28f4768da977f0e448009489617aec259180b63"
Expand Down

0 comments on commit eb1f942

Please sign in to comment.