From b0b0d55a1a4d40b085c311175d302499f56e0665 Mon Sep 17 00:00:00 2001 From: Seppdo <85109829+Seppdo@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:20:08 +0000 Subject: [PATCH] filebrowser: allow to use subdomain = false --- filebrowser/README.md | 13 +++++++++++++ filebrowser/main.tf | 25 +++++++++++++++++++++++-- filebrowser/run.sh | 7 +++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/filebrowser/README.md b/filebrowser/README.md index 2881376..e3a3d22 100644 --- a/filebrowser/README.md +++ b/filebrowser/README.md @@ -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 +} +``` \ No newline at end of file diff --git a/filebrowser/main.tf b/filebrowser/main.tf index a07072b..0065902 100644 --- a/filebrowser/main.tf +++ b/filebrowser/main.tf @@ -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." @@ -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 } @@ -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 } diff --git a/filebrowser/run.sh b/filebrowser/run.sh index 8744edb..e998c60 100644 --- a/filebrowser/run.sh +++ b/filebrowser/run.sh @@ -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"