Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit e2405d5

Browse files
authored
Sub domain proxy support (#2)
* Added port proxy domain support * Added proxy-domain to service file * Added sleep for clarity * TODO docs on proxy domain * Adjusted to only accept root domains
1 parent c899745 commit e2405d5

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ This script sets up a [Code Server](https://github.com/cdr/code-server) instance
2929
```
3030

3131
4. Access your Coder instance at your domain
32+
33+
## Port Proxy
34+
35+
Add more info here

code-server.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ After=network.target
55
[Service]
66
Type=exec
77
User=coder
8-
ExecStart=/usr/bin/code-server
8+
ExecStart=/usr/bin/code-server --proxy-domain mydomain.com
99
Restart=always
1010

1111
[Install]

setup.sh

+48-7
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,45 @@ echo " https://github.com/alec-hs/coder-cloudflare-setup"
99
echo
1010
echo "------------------------------------------------------------"
1111
echo
12-
read -s -p "Please enter a password for Coder web GUI: " password
13-
echo
14-
echo
15-
read -p "Please enter your domain: " domain
16-
echo
17-
read -s -p "Please enter your Cloudflare API Token: " token
12+
read -s -p "Enter a password for Coder web GUI: " password
13+
echo
14+
echo
15+
echo "Enter root domain to access Code Server (not a subdomain): "
16+
unset domain
17+
until [[ $domain =~ ^[A-Za-z0-9-]+.([A-Za-z]{3,}|[A-Za-z]{2}.[A-Za-z]{2}|[A-Za-z]{2})$ ]] ; do
18+
read -r domain
19+
done
20+
echo
21+
echo "To allow port proxying, subdomain setup will be used. Please"
22+
echo "enter a number from the below options. For more info:"
23+
echo "https://github.com/alec-hs/coder-cloudflare-setup/#port-proxy"
24+
echo
25+
echo " 0 - wildcard record"
26+
echo " 1 - specific ports"
27+
echo
28+
unset subOption
29+
until [[ $subOption == @(0|1) ]] ; do
30+
read -r -p "Your selection: " subOption
31+
done
32+
echo
33+
echo "Enter your proxy domain, eg: mydomain.com"
34+
read -p "Your domain: " proxyDomain
35+
if [ $subOption == 1 ]
36+
then
37+
echo "Enter a space separated list of all the ports you need."
38+
echo " eg: 80 8080 3000 8443"
39+
read -p "Your ports: " ports
40+
fi
41+
echo
42+
read -s -p "Enter your Cloudflare API Token: " token
1843
echo
1944
echo
2045
echo "------------------------------------------------------------"
2146
echo
2247
echo " Setting up Caddy and Coder services..."
2348
echo
2449
echo "------------------------------------------------------------"
50+
sleep 3
2551

2652
# Hash the password
2753
hash=$(printf $password | sha256sum | cut -d' ' -f1)
@@ -47,6 +73,9 @@ curl -fsSL https://code-server.dev/install.sh | sh
4773
# Download service file from repo
4874
curl https://raw.githubusercontent.com/alec-hs/coder-cloudflare-setup/main/code-server.service --output /etc/systemd/system/code-server.service
4975

76+
# Update coder file with proxy domain
77+
sed -i.bak "s/mydomain.com/$proxyDomain/" /etc/systemd/system/code-server.service
78+
5079
# Run Coder & run on boot
5180
systemctl enable --now code-server
5281

@@ -78,8 +107,20 @@ mv caddy /usr/bin
78107
curl https://raw.githubusercontent.com/alec-hs/coder-cloudflare-setup/main/Caddyfile --output /etc/caddy/Caddyfile
79108

80109
# Update Caddyfile
81-
sed -i.bak "s/sub.mydomain.com/$domain/" /etc/caddy/Caddyfile
82110
sed -i.bak "s/API_TOKEN/$token/" /etc/caddy/Caddyfile
111+
if [ $subOption == 0 ]
112+
then
113+
caddyDomains="$domain, *.$proxyDomain"
114+
fi
115+
if [ $subOption == 1 ]
116+
then
117+
proxyPorts="${ports// /.$proxyDomain, }"
118+
proxyPorts="$proxyPorts.$proxyDomain"
119+
caddyDomains="$domain, $proxyPorts"
120+
fi
121+
sed -i.bak "s/sub.mydomain.com/$caddyDomains/" /etc/caddy/Caddyfile
122+
123+
83124

84125
# Update Coder config in /home/coder/.config/code-server/config.yaml
85126
sed -i.bak "s/password: .*/hashed-password: $hash/" /home/coder/.config/code-server/config.yaml

0 commit comments

Comments
 (0)