Skip to content

Commit ce5a5b3

Browse files
Emyrkmatifali
andauthored
feat(vscode-web): support hosting on a subpath with subdomain=false (#288)
Co-authored-by: Muhammad Atif Ali <[email protected]> Co-authored-by: Muhammad Atif Ali <[email protected]>
1 parent 1b147ae commit ce5a5b3

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ You can test a module locally by updating the source as follows
4747
```tf
4848
module "example" {
4949
source = "git::https://github.com/<USERNAME>/<REPO>.git//<MODULE-NAME>?ref=<BRANCH-NAME>"
50+
# You may need to remove the 'version' field, it is incompatible with some sources.
5051
}
5152
```
5253

vscode-web/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Automatically install [Visual Studio Code Server](https://code.visualstudio.com/
1414
```tf
1515
module "vscode-web" {
1616
source = "registry.coder.com/modules/vscode-web/coder"
17-
version = "1.0.20"
17+
version = "1.0.22"
1818
agent_id = coder_agent.example.id
1919
accept_license = true
2020
}
@@ -29,7 +29,7 @@ module "vscode-web" {
2929
```tf
3030
module "vscode-web" {
3131
source = "registry.coder.com/modules/vscode-web/coder"
32-
version = "1.0.20"
32+
version = "1.0.22"
3333
agent_id = coder_agent.example.id
3434
install_prefix = "/home/coder/.vscode-web"
3535
folder = "/home/coder"
@@ -42,7 +42,7 @@ module "vscode-web" {
4242
```tf
4343
module "vscode-web" {
4444
source = "registry.coder.com/modules/vscode-web/coder"
45-
version = "1.0.20"
45+
version = "1.0.22"
4646
agent_id = coder_agent.example.id
4747
extensions = ["github.copilot", "ms-python.python", "ms-toolsai.jupyter"]
4848
accept_license = true
@@ -56,7 +56,7 @@ Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarte
5656
```tf
5757
module "vscode-web" {
5858
source = "registry.coder.com/modules/vscode-web/coder"
59-
version = "1.0.20"
59+
version = "1.0.22"
6060
agent_id = coder_agent.example.id
6161
extensions = ["dracula-theme.theme-dracula"]
6262
settings = {

vscode-web/main.tf

+22-3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ variable "auto_install_extensions" {
121121
default = false
122122
}
123123

124+
variable "subdomain" {
125+
type = bool
126+
description = <<-EOT
127+
Determines whether the app will be accessed via it's own subdomain or whether it will be accessed via a path on Coder.
128+
If wildcards have not been setup by the administrator then apps with "subdomain" set to true will not be accessible.
129+
EOT
130+
default = true
131+
}
132+
133+
data "coder_workspace_owner" "me" {}
134+
data "coder_workspace" "me" {}
135+
124136
resource "coder_script" "vscode-web" {
125137
agent_id = var.agent_id
126138
display_name = "VS Code Web"
@@ -138,6 +150,7 @@ resource "coder_script" "vscode-web" {
138150
EXTENSIONS_DIR : var.extensions_dir,
139151
FOLDER : var.folder,
140152
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
153+
SERVER_BASE_PATH : local.server_base_path,
141154
})
142155
run_on_start = true
143156

@@ -158,15 +171,21 @@ resource "coder_app" "vscode-web" {
158171
agent_id = var.agent_id
159172
slug = var.slug
160173
display_name = var.display_name
161-
url = var.folder == "" ? "http://localhost:${var.port}" : "http://localhost:${var.port}?folder=${var.folder}"
174+
url = local.url
162175
icon = "/icon/code.svg"
163-
subdomain = true
176+
subdomain = var.subdomain
164177
share = var.share
165178
order = var.order
166179

167180
healthcheck {
168-
url = "http://localhost:${var.port}/healthz"
181+
url = local.healthcheck_url
169182
interval = 5
170183
threshold = 6
171184
}
172185
}
186+
187+
locals {
188+
server_base_path = var.subdomain ? "" : format("/@%s/%s/apps/%s/", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.slug)
189+
url = var.folder == "" ? "http://localhost:${var.port}${local.server_base_path}" : "http://localhost:${var.port}${local.server_base_path}?folder=${var.folder}"
190+
healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz"
191+
}

vscode-web/run.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ if [ -n "${EXTENSIONS_DIR}" ]; then
1010
EXTENSION_ARG="--extensions-dir=${EXTENSIONS_DIR}"
1111
fi
1212

13+
# Set extension directory
14+
SERVER_BASE_PATH_ARG=""
15+
if [ -n "${SERVER_BASE_PATH}" ]; then
16+
SERVER_BASE_PATH_ARG="--server-base-path=${SERVER_BASE_PATH}"
17+
fi
18+
1319
run_vscode_web() {
14-
echo "👷 Running $VSCODE_WEB serve-local $EXTENSION_ARG --port ${PORT} --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..."
20+
echo "👷 Running $VSCODE_WEB serve-local $EXTENSION_ARG $SERVER_BASE_PATH_ARG --port ${PORT} --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..."
1521
echo "Check logs at ${LOG_PATH}!"
16-
"$VSCODE_WEB" serve-local "$EXTENSION_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 &
22+
"$VSCODE_WEB" serve-local "$EXTENSION_ARG" "$SERVER_BASE_PATH_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 &
1723
}
1824

1925
# Check if the settings file exists...

0 commit comments

Comments
 (0)