Brief
VSCode is popular, but not suitable for iPad in a native manner. This tutorial will show you how to deploy a VSCode server and connect to it on your iPad in a browser, say Google Chrome.
Preliminaries
- VSCodium: an open-sourced version of VSCode. Isn’t VSCode already an open-sourced project? Yes, and no. The full source code published in github.com, whereas the binaries to downloads are not. These official binaries refer quite some proprietary libraries, say InteliSense for C++/Java/Python. Without them, we can barely do the coding.
- Code-server: a headless version of VSCodium running on any modern Linux distribution. We will deploy it on a Linux server.
- Certbot: an easy daemon to manage HTTPS certificates for us. It depends on snapd, a great package manager.
Recipe
Suppose we are on a Ubuntu/Debian. By executing the bash scripts below, we can deploy Code-server and make VSCode working on an iPad browser.
Step 0: set environments
DOMAIN_NAME="mycode.linuxtechtoday.com" # <-- NOTE: change it to the real domain name
LOCAL_PORT="8089" # <-- Don't have to change. The local port code-server listens to
LOGIN_TOKEN="117ee8a170a32b7d0f90aa3b64946df92acdf99a" # <-- CHANGE IT! Password to login into VSCode in browser
Step 1: deploy code-server (should be executed under the user other than root)
curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_amd64.deb
sudo dpkg -i code-server_${VERSION}_amd64.deb
mkdir -p $HOME/.config/code-server
cat<<EOL>$HOME/.config/code-server/config.yaml
bind-addr: 127.0.0.1:$PORT
auth: password
password:$LOGIN_TOKEN
cert: false
EOL
sudo systemctl enable --now code-server@$USER
sudo systemctl start code-server@$USER
Step 2: install Nginx
sudo apt install -y nginx
cat<<EOL>.tmp-code-server.nginx
server {
listen 80;
server_name $DOMAIN_NAME;
root /usr/share/nginx/html;
location / {
proxy_pass http://127.0.0.1:$LOCAL_PORT/;
proxy_set_header Host \$host;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
}
}
EOL
sudo mv .tmp-code-server.nginx /etc/nginx/sites-enables/code-server
Step 3: configure HTTPS
We have to install certbot, and then run it.
Install certbot:
sudo bash -c 'apt update && apt install snapd && snap install --classic certbot'
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx
Choose the domain defined above, and let certbot do her job.
Done.