feat: add support for custom URL paths via BASE_URL configuration#1451
Open
roberfi wants to merge 1 commit intoplankanban:masterfrom
Open
feat: add support for custom URL paths via BASE_URL configuration#1451roberfi wants to merge 1 commit intoplankanban:masterfrom
roberfi wants to merge 1 commit intoplankanban:masterfrom
Conversation
Enable Planka to be deployed under custom URL paths (e.g., /planka) by implementing runtime configuration injection from the BASE_URL environment variable. This allows deployment behind reverse proxies with path-based routing without requiring image rebuilds.
Member
|
Hey! Thanks for your PR 🙏 I'll definitely check and test it soon. We're in the middle of preparing the final v2 release, so it might take a bit of time to get to everything. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1156 and #1323
This PR adds support for deploying Planka under custom URL paths by extracting the path from the
BASE_URLenvironment variable and injecting it into the client at runtime.Problem
Previously, Planka could only be deployed at the root path (
/). Users wanting to deploy it under a subpath (e.g.,/planka) behind a reverse proxy had to rebuild the Docker image with build-time environment variables, which is not feasible for users pulling pre-built images.Solution
Architecture Changes
Runtime Configuration Injection
inject-config-template.sh) that converts the Vite-builtindex.htmlinto an EJS templateindex/show) that injectsbaseUrlPathfrom server config into the templatewindow.PLANKA_CONFIGat runtimePath Handling
SERVER_BASE_URLwith runtimeBASE_PATHthroughout the clientPaths.js) to use the dynamic base pathCookie Path Fix
/) and subpath deployments'/'whenbaseUrlPathis empty to ensure valid cookie pathshttpOnlyToken) and client-side (accessToken) cookiesTechnical Details
Server changes:
server/config/custom.js: Extract and strip trailing slash fromBASE_URLpathnameserver/inject-config-template.sh: AWK script to inject EJS template into HTML (new file)server/api/controllers/index/show.js: Controller that passesbaseUrlPathto the view (new file)server/config/routes.js: Changedindexfrom direct view rendering to controller actionserver/config/views.js: Changed extension from.htmlto.ejsserver/config/policies.js: Added public access policy forindex/showcontrollerserver/api/helpers/utils/set-http-only-token-cookie.js: Added|| '/'fallback for cookie pathClient changes:
client/src/constants/Config.js: ReadBASE_PATHfromwindow.PLANKA_CONFIG.baseUrlPathat runtimeclient/src/constants/Paths.js: PrependBASE_PATHto all route definitionsclient/src/api/http.js: UseBASE_PATHinstead ofSERVER_BASE_URLfor API callsclient/src/api/socket.js: ConfigureSocket.IOpath withBASE_PATHprefixclient/src/utils/access-token-storage.js: Set proper cookie paths with fallback to'/'client/vite.config.js: Setbase: './'for relative asset pathsBuild changes:
Dockerfile: Transformindex.htmltoindex.ejstemplate during image buildTesting
Tested with the following
nginxconfiguration:And this
BASE_URLenvironment variable indocker-compose.yml:Breaking Changes
None. Existing deployments at root path continue to work without any configuration changes.
Additional note
This is my first contribution to the project. If something is wrong, missing or anyone has a better idea to implement this, please let me know and I'll adapt my changes to your needs.