Refactor URL handling in vscode-web module

- Consolidates URL and path logic using locals.
- Simplifies script syntax, improving maintainability.
pull/288/head
Muhammad Atif Ali 9 months ago
parent eb95ea41ab
commit aa3d9b8a7a

@ -150,8 +150,7 @@ resource "coder_script" "vscode-web" {
EXTENSIONS_DIR : var.extensions_dir, EXTENSIONS_DIR : var.extensions_dir,
FOLDER : var.folder, FOLDER : var.folder,
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions, AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
SERVER_BASE_PATH : var.subdomain ? "" : format("/@%s/%s/apps/vscode-web/", SERVER_BASE_PATH : local.server_base_path,
data.coder_workspace_owner.me.name, data.coder_workspace.me.name),
}) })
run_on_start = true run_on_start = true
@ -172,16 +171,21 @@ resource "coder_app" "vscode-web" {
agent_id = var.agent_id agent_id = var.agent_id
slug = var.slug slug = var.slug
display_name = var.display_name display_name = var.display_name
url = local.url
url = var.folder == "" ? "http://localhost:${var.port}" : "http://localhost:${var.port}?folder=${var.folder}" icon = "/icon/code.svg"
icon = "/icon/code.svg" subdomain = var.subdomain
subdomain = var.subdomain share = var.share
share = var.share order = var.order
order = var.order
healthcheck { healthcheck {
url = "http://localhost:${var.port}/healthz" url = local.healthcheck_url
interval = 5 interval = 5
threshold = 6 threshold = 6
} }
} }
locals {
server_base_path = var.subdomain ? "" : format("/@%s/%s/apps/%s/", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.slug)
url = var.folder == "" ? "http://localhost:${var.port}${local.server_base_path}" : "http://localhost:${var.port}${local.server_base_path}?folder=${var.folder}"
healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz"
}

Loading…
Cancel
Save