Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix(admin): respect urlPrefix for root redirect and JS API calls (#8975)

Chris Lub0e79ad207a5
diff --git a/weed/admin/static/js/admin.js b/weed/admin/static/js/admin.js
index 2633cb5b22..1160790b5b 100644
--- a/weed/admin/static/js/admin.js
+++ b/weed/admin/static/js/admin.js
@@ -1267,7 +1267,7 @@ async function submitUploadFile() {
});
// Send request
- xhr.open('POST', '/api/files/upload');
+ xhr.open('POST', basePath('/api/files/upload'));
xhr.send(formData);
} catch (error) {
@@ -1320,7 +1320,7 @@ function exportFileList() {
// Download file
function downloadFile(filePath) {
// Create download link using admin API
- const downloadUrl = `/api/files/download?path=${encodeURIComponent(filePath)}`;
+ const downloadUrl = basePath(`/api/files/download?path=${encodeURIComponent(filePath)}`);
window.open(downloadUrl, '_blank');
}
@@ -1786,7 +1786,7 @@ function createFileViewerContent(file, content) {
if (file.mime.startsWith('image/')) {
return `
<div class="text-center">
- <img src="/api/files/download?path=${encodeURIComponent(file.full_path)}"
+ <img src="${basePath('/api/files/download?path=' + encodeURIComponent(file.full_path))}"
class="img-fluid" alt="${file.name}" style="max-height: 500px;">
</div>
`;
@@ -1804,7 +1804,7 @@ function createFileViewerContent(file, content) {
} else if (file.mime === 'application/pdf') {
return `
<div class="text-center">
- <embed src="/api/files/download?path=${encodeURIComponent(file.full_path)}"
+ <embed src="${basePath('/api/files/download?path=' + encodeURIComponent(file.full_path))}"
type="application/pdf" width="100%" height="500px">
</div>
`;
diff --git a/weed/command/admin.go b/weed/command/admin.go
index fca5524e11..31ddd7a2c8 100644
--- a/weed/command/admin.go
+++ b/weed/command/admin.go
@@ -392,7 +392,19 @@ func startAdminServer(ctx context.Context, options AdminOptions, enableUI bool,
addr := fmt.Sprintf(":%d", *options.port)
var handler http.Handler = r
if urlPrefix != "" {
- handler = http.StripPrefix(urlPrefix, r)
+ stripped := http.StripPrefix(urlPrefix, r)
+ handler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+ // Redirect /prefix (no trailing slash) to /prefix/
+ if req.URL.Path == urlPrefix {
+ target := urlPrefix + "/"
+ if req.URL.RawQuery != "" {
+ target += "?" + req.URL.RawQuery
+ }
+ http.Redirect(w, req, target, http.StatusFound)
+ return
+ }
+ stripped.ServeHTTP(w, req)
+ })
}
server := &http.Server{
Addr: addr,