-
Notifications
You must be signed in to change notification settings - Fork 146
Adds support for path prefix configuration #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eduardolat
merged 6 commits into
eduardolat:develop
from
PatrikScully:feature/path-prefix
Oct 5, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e0447d
Adds support for path prefix configuration
PatrikScully e91d202
Refactors pathutil test suite for better isolation
PatrikScully 6965e14
Supports subdirectory deployment with configurable path prefix
PatrikScully 7658e21
Refactors URL paths using pathutil.BuildPath function
PatrikScully 7b81f8a
Standardizes URL path formatting in dashboard components
PatrikScully f39598d
Refactors URL handling with pathutil.BuildPath
PatrikScully File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package pathutil | ||
|
|
||
| import "sync" | ||
|
|
||
| var ( | ||
| pathPrefix string | ||
| pathPrefixOnce sync.Once | ||
| ) | ||
|
|
||
| // SetPathPrefix sets the path prefix once. This should be called during | ||
| // application initialization with the value from the environment config. | ||
| func SetPathPrefix(prefix string) { | ||
| pathPrefixOnce.Do(func() { | ||
| pathPrefix = prefix | ||
| }) | ||
| } | ||
|
|
||
| // GetPathPrefix returns the configured path prefix. | ||
| func GetPathPrefix() string { | ||
| return pathPrefix | ||
| } | ||
|
|
||
| // BuildPath constructs a full path by prepending the configured path prefix | ||
| // to the given path. If no prefix is configured, returns the path as-is. | ||
| // | ||
| // Examples: | ||
| // - BuildPath("/dashboard") with prefix "/pgbackweb" -> "/pgbackweb/dashboard" | ||
| // - BuildPath("/dashboard") with no prefix -> "/dashboard" | ||
| // - BuildPath("") with prefix "/pgbackweb" -> "/pgbackweb" | ||
| func BuildPath(path string) string { | ||
| if pathPrefix == "" { | ||
| return path | ||
| } | ||
| return pathPrefix + path | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package pathutil | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestBuildPath(t *testing.T) { | ||
| t.Helper() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| prefix string | ||
| path string | ||
| expected string | ||
| shouldSkip bool // Skip if prefix was already set | ||
| }{ | ||
| { | ||
| name: "no prefix configured", | ||
| prefix: "", | ||
| path: "/dashboard", | ||
| expected: "/dashboard", | ||
| }, | ||
| { | ||
| name: "with prefix - dashboard", | ||
| prefix: "/pgbackweb", | ||
| path: "/dashboard", | ||
| expected: "/pgbackweb/dashboard", | ||
| }, | ||
| { | ||
| name: "with prefix - api", | ||
| prefix: "/pgbackweb", | ||
| path: "/api/v1/health", | ||
| expected: "/pgbackweb/api/v1/health", | ||
| }, | ||
| { | ||
| name: "with prefix - root", | ||
| prefix: "/pgbackweb", | ||
| path: "", | ||
| expected: "/pgbackweb", | ||
| }, | ||
| { | ||
| name: "with prefix - auth", | ||
| prefix: "/pgbackweb", | ||
| path: "/auth/login", | ||
| expected: "/pgbackweb/auth/login", | ||
| }, | ||
| { | ||
| name: "empty prefix and empty path", | ||
| prefix: "", | ||
| path: "", | ||
| expected: "", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| // Reset for each test | ||
| pathPrefix = tt.prefix | ||
| result := BuildPath(tt.path) | ||
| if result != tt.expected { | ||
| t.Errorf("BuildPath(%q) with prefix %q = %q, want %q", tt.path, tt.prefix, result, tt.expected) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGetPathPrefix(t *testing.T) { | ||
| t.Helper() | ||
|
|
||
| // Set a test prefix | ||
| pathPrefix = "/test-prefix" | ||
|
|
||
| result := GetPathPrefix() | ||
| if result != "/test-prefix" { | ||
| t.Errorf("GetPathPrefix() = %q, want %q", result, "/test-prefix") | ||
| } | ||
|
|
||
| // Reset | ||
| pathPrefix = "" | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package validate | ||
|
|
||
| import "strings" | ||
|
|
||
| // PathPrefix validates that a path prefix is correctly formatted. | ||
| // | ||
| // Valid path prefixes: | ||
| // - Empty string (no prefix) | ||
| // - Must start with / | ||
| // - Must NOT end with / | ||
| // - No whitespace allowed | ||
| // | ||
| // Examples: | ||
| // - "" -> true (no prefix) | ||
| // - "/api" -> true | ||
| // - "/pgbackweb" -> true | ||
| // - "/app/v1" -> true | ||
| // - "api" -> false (doesn't start with /) | ||
| // - "/api/" -> false (ends with /) | ||
| // - "/ api" -> false (contains whitespace) | ||
| func PathPrefix(pathPrefix string) bool { | ||
| // Empty string is valid (no prefix) | ||
| if pathPrefix == "" { | ||
| return true | ||
| } | ||
|
|
||
| // Must start with / | ||
| if !strings.HasPrefix(pathPrefix, "/") { | ||
| return false | ||
| } | ||
|
|
||
| // Must NOT end with / | ||
| if strings.HasSuffix(pathPrefix, "/") { | ||
| return false | ||
| } | ||
|
|
||
| // No whitespace allowed | ||
| if strings.ContainsAny(pathPrefix, " \t\n\r") { | ||
| return false | ||
| } | ||
|
|
||
| return true | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package validate | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestPathPrefix(t *testing.T) { | ||
| t.Helper() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| input string | ||
| expected bool | ||
| }{ | ||
| { | ||
| name: "empty string is valid", | ||
| input: "", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "valid simple path", | ||
| input: "/api", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "valid complex path", | ||
| input: "/pgbackweb", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "valid nested path", | ||
| input: "/app/v1", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "valid deep nested path", | ||
| input: "/api/app/v1", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "invalid - doesn't start with slash", | ||
| input: "api", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "invalid - ends with slash", | ||
| input: "/api/", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "invalid - only slash", | ||
| input: "/", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "invalid - contains space", | ||
| input: "/api path", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "invalid - contains tab", | ||
| input: "/api\tpath", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "invalid - contains newline", | ||
| input: "/api\npath", | ||
| expected: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := PathPrefix(tt.input) | ||
| if result != tt.expected { | ||
| t.Errorf("PathPrefix(%q) = %v, want %v", tt.input, result, tt.expected) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.