mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 16:55:59 +03:00
[PR #3449] [MERGED] feat: support for subpath based access in SH apps #4388
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#4388
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/3449
Author: @jamesgeorge007
Created: 10/12/2023
Status: ✅ Merged
Merged: 11/22/2023
Merged by: @AndrewBastin
Base:
release/2023.12.0← Head:feat/subpath-based-access📝 Commits (10+)
b212479refactor: make service worker ignore important routes4fb351dchore: update aio Caddyfile6023cf0chore: convey the base route as admin where sh-admin gets servedc46fea8fix: ensure any non-existent file in the server is routed to the corresponding SPAd8f7647build: generate build with admin as the base for subpath based access2170037refactor: infer base URL from the BASE_URL env var across the appae71134chore: add TODO comment for pending Caddy configurations and port updates671cd01chore: generate multiple builds for sh-admin7e10004chore: dedicated Caddyfiles based on AIO container launch strategies15468a1feat: subpath access for individual containers📊 Changes
18 files changed (+262 additions, -48 deletions)
View changed files
📝
.env.example(+3 -0)➕
aio-multiport-setup.Caddyfile(+19 -0)➕
aio-subpath-access.Caddyfile(+37 -0)➖
aio.Caddyfile(+0 -11)📝
aio_run.mjs(+2 -1)📝
docker-compose.yml(+7 -3)➕
packages/hoppscotch-backend/backend.Caddyfile(+3 -0)➕
packages/hoppscotch-backend/prod_run.mjs(+66 -0)📝
packages/hoppscotch-selfhost-web/Caddyfile(+3 -3)➕
packages/hoppscotch-selfhost-web/selfhost-web.Caddyfile(+5 -0)📝
packages/hoppscotch-selfhost-web/vite.config.ts(+2 -0)📝
packages/hoppscotch-sh-admin/Caddyfile(+3 -3)📝
packages/hoppscotch-sh-admin/prod_run.mjs(+64 -12)➕
packages/hoppscotch-sh-admin/sh-admin-multiport-setup.Caddyfile(+5 -0)➕
packages/hoppscotch-sh-admin/sh-admin-subpath-access.Caddyfile(+11 -0)📝
packages/hoppscotch-sh-admin/src/modules/router.ts(+1 -1)📝
packages/hoppscotch-sh-admin/src/pages/_.vue(+3 -1)📝
prod.Dockerfile(+28 -13)📄 Description
Description
This PR includes the changes for providing subpath-based access support in the AIO container and for individual containers. Two builds are generated for
sh-adminto make the transition from/to subpath-based access seamless. The idea is to not call for the need to rebuild the containers while switching between multiport setup and subpath-based access.Closes HFE-252 HBE-283 HBE-284.
Changes
Makes the service worker ignore the
/admin/*and/backend/*routes such that it is always fetched from the network. The reverse proxy takes control and routes it to the corresponding service.Two builds are generated for
sh-admin:/as the base path - is generated indist-multiport-setup./adminset as the base path and the necessary prefixes added wherever necessary (/adminfor images within the public directory and set it as a base while initializing the Vue router module so the SPA considers part of the route that appears after/admin) - generated indist-subpath-access.dist->/site/-sh-admin-multiport-setupdist-subpath-access->/site/sh-admin-subpath-accessDedicated Caddyfiles are introduced for the AIO container corresponding to the different launch strategies (multiport setup and subpath-based access).
aio-subpath-access.Caddyfileselfhost-webSPA is served on the root path/by default.sh-adminSPA is served at the/adminpath. It serves the static files from/site/sh-admin-subpath-accesswith/adminas the base path./backendare reverse proxied to port8080, where the server is up and running.sh-adminwhen you initiate a full reload while on a specific route that lacks a corresponding HTML file on the server's file system, the request is redirected to the root path. This redirection is achieved by leveraging Caddy'stry_filesdirective. As a result, control is gracefully handed back to the SPA, allowing it to handle and render the appropriate view according to the requested route. Similarly, for "selfhost-web," we have implemented a catch-all route strategy.404on visiting ports3000and3100.aio-multiport-setup.Caddyfileaio.Caddyfileservingselfhost-webon port3000andsh-adminlegacy build on port3100.404on visiting port3080that maps to port80in the container.Introduces 2 Caddyfiles for
sh-admin,sh-admin-multiport-setup.Caddyfile&sh-admin-subpath-access.Caddyfile. Both listen on ports3100&80(standard HTTP ingress port) and serve the respective directories (multiport setup/subpath-based access).For the backend container, a new Caddyfile is added,
backend.Caddyfile-> Acts as a reverse proxy on ports80(standard HTTP ingress port) and3170and forwards them tolocalhost:8080where the backend server is up and running.Additional Caddyfile added for
selfhost-web,selfhost-web.Caddyfilethat listens on ports (standard HTTP ingress port)80&3000and serves the static files.The user needs to maintain a reverse proxy in front to achieve the subpath-based access behavior for individual containers. For instance, refer to the below Caddyfile.
A
404page is displayed if attempting to visit thesh-adminservice individually fromlocalhost:3100orlocalhost:3280while opting for subpath-based access since the build served is supposed to be from/admin.Steps to verify
AIO container with multiport setup
Make the following updates to
.env.Access services
selfhost-web->localhost:3000sh-admin->localhost:3100backend->localhost:3170AIO container with subpath-based access enabled
Make the following updates to
.env.Access services
selfhost-web->localhost:3080sh-admin->localhost:3080/adminbackend->localhost:3080/backendselfhost-web->docker compose up hoppscotch-app.sh-admin->docker compose up hoppscotch-sh-admin.backend->docker compose up hoppscotch-backend(Optional since the above stages have this as a dependency).Individual containers with multiport setup and bound to legacy ports.
Make the following updates to
.env.Access services
selfhost-web->localhost:3000sh-admin->localhost:3100backend->localhost:3170Individual containers with multiport setup and bound standard HTTP port (80)
Make the following updates to
.env.Access services
selfhost-web->localhost:3080sh-admin->localhost:3280backend->localhost:3180Individual containers with subpath-based access enabled bound to legacy ports & standard HTTP port (80)
Add a
Caddyfileto the root path.Make the following updates to
.env.Spin up the individual containers and start Caddy with
caddy runat the path where the aboveCaddyfileexists to access the services.selfhost-web->localhost:3500sh-admin->localhost:3500/adminbackend->localhost:3500/backendChecks
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
TeamEnvironmentsService#4777