From 8703a0dcfde72ff3758e8d4143558108b1f694ee Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 24 Oct 2023 13:52:22 +0530 Subject: [PATCH] build: generate build with admin as the base for subpath based access --- .env.example | 3 +++ packages/hoppscotch-sh-admin/src/modules/router.ts | 4 +++- packages/hoppscotch-sh-admin/src/pages/_.vue | 5 ++++- packages/hoppscotch-sh-admin/vite.config.ts | 1 - 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 56a4e0016..e962469a0 100644 --- a/.env.example +++ b/.env.example @@ -59,3 +59,6 @@ VITE_BACKEND_API_URL=http://localhost:3170/v1 # Terms Of Service And Privacy Policy Links (Optional) VITE_APP_TOS_LINK=https://docs.hoppscotch.io/support/terms VITE_APP_PRIVACY_POLICY_LINK=https://docs.hoppscotch.io/support/privacy + +# Set to `true` for subpath based access +VITE_INCLUDE_ADMIN_PREFIX=false diff --git a/packages/hoppscotch-sh-admin/src/modules/router.ts b/packages/hoppscotch-sh-admin/src/modules/router.ts index 28404f55c..e07cc5b2b 100644 --- a/packages/hoppscotch-sh-admin/src/modules/router.ts +++ b/packages/hoppscotch-sh-admin/src/modules/router.ts @@ -41,8 +41,10 @@ export const isLoadingInitialRoute = readonly(_isLoadingInitialRoute); export default { onVueAppInit(app) { + const basePath = import.meta.env.PROD && import.meta.env.VITE_INCLUDE_ADMIN_PREFIX === 'true' ? '/admin' : undefined + const router = createRouter({ - history: createWebHistory('/admin'), + history: createWebHistory(basePath), routes, }); diff --git a/packages/hoppscotch-sh-admin/src/pages/_.vue b/packages/hoppscotch-sh-admin/src/pages/_.vue index 7a4ce25e2..c7c607622 100644 --- a/packages/hoppscotch-sh-admin/src/pages/_.vue +++ b/packages/hoppscotch-sh-admin/src/pages/_.vue @@ -6,7 +6,7 @@ :class="{ 'min-h-screen': statusCode !== 404 }" > props.error?.statusCode ?? 404); const message = computed( diff --git a/packages/hoppscotch-sh-admin/vite.config.ts b/packages/hoppscotch-sh-admin/vite.config.ts index 1722c2b3e..c19cce8f7 100644 --- a/packages/hoppscotch-sh-admin/vite.config.ts +++ b/packages/hoppscotch-sh-admin/vite.config.ts @@ -15,7 +15,6 @@ import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'; export default defineConfig({ envPrefix: process.env.HOPP_ALLOW_RUNTIME_ENV ? 'VITE_BUILDTIME_' : 'VITE_', envDir: path.resolve(__dirname, '../..'), - base: '/admin/', server: { port: 3100, },