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

Commit 834ffde

Browse files
Seppdomatifali
andauthored
feat(filebrowser): support subdomain = false (#286)
Co-authored-by: Muhammad Atif Ali <[email protected]>
1 parent 831f64d commit 834ffde

File tree

4 files changed

+74
-9
lines changed

4 files changed

+74
-9
lines changed

filebrowser/README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ A file browser for your workspace.
1313

1414
```tf
1515
module "filebrowser" {
16-
source = "registry.coder.com/modules/filebrowser/coder"
17-
version = "1.0.8"
18-
agent_id = coder_agent.example.id
16+
source = "registry.coder.com/modules/filebrowser/coder"
17+
version = "1.0.8"
18+
agent_id = coder_agent.example.id
19+
agent_name = "main"
1920
}
2021
```
2122

@@ -27,10 +28,11 @@ module "filebrowser" {
2728

2829
```tf
2930
module "filebrowser" {
30-
source = "registry.coder.com/modules/filebrowser/coder"
31-
version = "1.0.8"
32-
agent_id = coder_agent.example.id
33-
folder = "/home/coder/project"
31+
source = "registry.coder.com/modules/filebrowser/coder"
32+
version = "1.0.8"
33+
agent_id = coder_agent.example.id
34+
agent_name = "main"
35+
folder = "/home/coder/project"
3436
}
3537
```
3638

@@ -41,6 +43,18 @@ module "filebrowser" {
4143
source = "registry.coder.com/modules/filebrowser/coder"
4244
version = "1.0.8"
4345
agent_id = coder_agent.example.id
46+
agent_name = "main"
4447
database_path = ".config/filebrowser.db"
4548
}
4649
```
50+
51+
### Serve from the same domain (no subdomain)
52+
53+
```tf
54+
module "filebrowser" {
55+
source = "registry.coder.com/modules/filebrowser/coder"
56+
agent_id = coder_agent.example.id
57+
agent_name = "main"
58+
subdomain = false
59+
}
60+
```

filebrowser/main.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ describe("filebrowser", async () => {
1111

1212
testRequiredVariables(import.meta.dir, {
1313
agent_id: "foo",
14+
agent_name: "main",
1415
});
1516

1617
it("fails with wrong database_path", async () => {
1718
const state = await runTerraformApply(import.meta.dir, {
1819
agent_id: "foo",
20+
agent_name: "main",
1921
database_path: "nofb",
2022
}).catch((e) => {
2123
if (!e.message.startsWith("\nError: Invalid value for variable")) {
@@ -27,6 +29,7 @@ describe("filebrowser", async () => {
2729
it("runs with default", async () => {
2830
const state = await runTerraformApply(import.meta.dir, {
2931
agent_id: "foo",
32+
agent_name: "main",
3033
});
3134
const output = await executeScriptInContainer(state, "alpine");
3235
expect(output.exitCode).toBe(0);
@@ -48,6 +51,7 @@ describe("filebrowser", async () => {
4851
it("runs with database_path var", async () => {
4952
const state = await runTerraformApply(import.meta.dir, {
5053
agent_id: "foo",
54+
agent_name: "main",
5155
database_path: ".config/filebrowser.db",
5256
});
5357
const output = await executeScriptInContainer(state, "alpine");
@@ -70,6 +74,7 @@ describe("filebrowser", async () => {
7074
it("runs with folder var", async () => {
7175
const state = await runTerraformApply(import.meta.dir, {
7276
agent_id: "foo",
77+
agent_name: "main",
7378
folder: "/home/coder/project",
7479
});
7580
const output = await executeScriptInContainer(state, "alpine");
@@ -88,4 +93,27 @@ describe("filebrowser", async () => {
8893
"📝 Logs at /tmp/filebrowser.log",
8994
]);
9095
});
96+
97+
it("runs with subdomain=false", async () => {
98+
const state = await runTerraformApply(import.meta.dir, {
99+
agent_id: "foo",
100+
agent_name: "main",
101+
subdomain: false,
102+
});
103+
const output = await executeScriptInContainer(state, "alpine");
104+
expect(output.exitCode).toBe(0);
105+
expect(output.stdout).toEqual([
106+
"\u001B[0;1mInstalling filebrowser ",
107+
"",
108+
"🥳 Installation complete! ",
109+
"",
110+
"👷 Starting filebrowser in background... ",
111+
"",
112+
"📂 Serving /root at http://localhost:13339 ",
113+
"",
114+
"Running 'filebrowser --noauth --root /root --port 13339' ",
115+
"",
116+
"📝 Logs at /tmp/filebrowser.log",
117+
]);
118+
});
91119
});

filebrowser/main.tf

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ variable "agent_id" {
1414
description = "The ID of a Coder agent."
1515
}
1616

17+
data "coder_workspace" "me" {}
18+
19+
data "coder_workspace_owner" "me" {}
20+
21+
variable "agent_name" {
22+
type = string
23+
description = "The name of the main deployment. (Used to build the subpath for coder_app.)"
24+
}
25+
1726
variable "database_path" {
1827
type = string
1928
description = "The path to the filebrowser database."
@@ -58,6 +67,15 @@ variable "order" {
5867
default = null
5968
}
6069

70+
variable "subdomain" {
71+
type = bool
72+
description = <<-EOT
73+
Determines whether the app will be accessed via it's own subdomain or whether it will be accessed via a path on Coder.
74+
If wildcards have not been setup by the administrator then apps with "subdomain" set to true will not be accessible.
75+
EOT
76+
default = true
77+
}
78+
6179
resource "coder_script" "filebrowser" {
6280
agent_id = var.agent_id
6381
display_name = "File Browser"
@@ -67,7 +85,9 @@ resource "coder_script" "filebrowser" {
6785
PORT : var.port,
6886
FOLDER : var.folder,
6987
LOG_PATH : var.log_path,
70-
DB_PATH : var.database_path
88+
DB_PATH : var.database_path,
89+
SUBDOMAIN : var.subdomain,
90+
SERVER_BASE_PATH : var.subdomain ? "" : format("/@%s/%s.%s/apps/filebrowser", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.agent_name),
7191
})
7292
run_on_start = true
7393
}
@@ -78,7 +98,7 @@ resource "coder_app" "filebrowser" {
7898
display_name = "File Browser"
7999
url = "http://localhost:${var.port}"
80100
icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg"
81-
subdomain = true
101+
subdomain = var.subdomain
82102
share = var.share
83103
order = var.order
84104
}

filebrowser/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ if [ "${DB_PATH}" != "filebrowser.db" ]; then
1717
DB_FLAG=" -d ${DB_PATH}"
1818
fi
1919

20+
# set baseurl to be able to run if sudomain=false; if subdomain=true the SERVER_BASE_PATH value will be ""
21+
filebrowser config set --baseurl "${SERVER_BASE_PATH}" > ${LOG_PATH} 2>&1
22+
2023
printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n"
2124

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

0 commit comments

Comments
 (0)