Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

feat(filebrowser): support subdomain = false #286

Merged
merged 21 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions filebrowser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ module "filebrowser" {
database_path = ".config/filebrowser.db"
}
```

### Serve from the same domain (no subdomain)

Make sure to set both workspace_name and owner_name.

```tf
module "filebrowser" {
source = "registry.coder.com/modules/filebrowser/coder"
agent_id = coder_agent.main.id
workspace_name = data.coder_workspace.me.name
owner_name = data.coder_workspace_owner.me.name
}
```
Copy link
Member

@matifali matifali Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also update the example accordingly.

25 changes: 23 additions & 2 deletions filebrowser/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ variable "agent_id" {
description = "The ID of a Coder agent."
}

variable "workspace_name" {
type = string
default = ""
description = "Set this and owner_name to serve filebrowser from subdirectory."
}

variable "owner_name" {
type = string
default = ""
description = "Set this and workspace_name to serve filebrowser from subdirectory."
}

variable "resource_name" {
type = string
default = "main"
description = "The name of the main deployment. (Used to build the subdirectory of the module.)"
}

variable "database_path" {
type = string
description = "The path to the filebrowser database."
Expand Down Expand Up @@ -67,7 +85,10 @@ resource "coder_script" "filebrowser" {
PORT : var.port,
FOLDER : var.folder,
LOG_PATH : var.log_path,
DB_PATH : var.database_path
DB_PATH : var.database_path,
WORKSPACE_NAME : var.workspace_name,
OWNER_NAME : var.owner_name,
RESOURCE_NAME : var.resource_name
})
run_on_start = true
}
Expand All @@ -78,7 +99,7 @@ resource "coder_app" "filebrowser" {
display_name = "File Browser"
url = "http://localhost:${var.port}"
icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg"
subdomain = true
subdomain = var.owner_name == "" && var.workspace_name == ""
share = var.share
order = var.order
}
7 changes: 7 additions & 0 deletions filebrowser/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ if [ "${DB_PATH}" != "filebrowser.db" ]; then
DB_FLAG=" -d ${DB_PATH}"
fi

# set baseurl if subdomain = false (owner_name and workspace_name is set), else reset to "" for use with subdomain = true
if [ "${OWNER_NAME}" != "" ] && [ "${WORKSPACE_NAME}" != "" ]; then
filebrowser config set --baseurl "/@${OWNER_NAME}/${WORKSPACE_NAME}.${RESOURCE_NAME}/apps/filebrowser" > ${LOG_PATH} 2>&1
else
filebrowser config set --baseurl "" > ${LOG_PATH} 2>&1
fi

printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n"

printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"
Expand Down