Colocate multiple Deno modules on the same Docker container using wildcard DNS, URL path, HTTP headers, and more.
You can easily deploy it as a Dockerized web service to cloud-hosting providers such as render.com.
Just fork this repository on your GitHub account and select it on your cloud hosting platform.
Then setup environment variables (see list below)
After deploy, if your hosting supports it, you can setup a custom domain with a wildcard.
e.g. *.node0.hazae41.me
-> mydocker.onrender.com
You just need
- Docker (e.g. for Ubuntu)
- Make (e.g.
sudo apt-get install make
) - Git (e.g.
sudo apt-get install git
)
Then clone the repository (or fork-then-clone)
git clone --recurse-submodules https://github.com/hazae41/example-microserver <name> && cd ./<name>
Setup environment variables (see list below) by creating a .env.local
file
cp ./.env.example ./.env.local && nano ./.env.local
You can then:
- Build the latest commit and latest environment variables
make build
- Start and open console (kill with ctrl+c; close with ctrl+p then ctrl+q)
make start
- Show logs
make logs
- Open console (kill with ctrl+c; close with ctrl+p then ctrl+q)
make open
- Stop all instances
make stop
- Clean all builds
make clean
- Update to latest version
git reset --hard && git checkout $(git tag | sort -V | tail -1)
You can enable HTTPS by either using Cloudflare as a HTTPS-to-HTTP reverse proxy, by configuring Nginx as a HTTPS-to-HTTP reverse proxy on your node, or by setting CERT
and KEY
.
Don't set if cloud-hosting
The exposed port
e.g. 8080
Don't set if cloud-hosting
The paths to your TLS certificate and private key
e.g. ./tls/fullchain.pem
and ./tls/privkey.pem
Each submodule is configured via environment variables with a dedicated prefix. And routes requests to it via wildcard DNS, URL path, HTTP headers, and more.
git submodule add https://github.com/<...> ./mods/<name>
e.g.
git submodule add https://github.com/hazae41/network-signaler.git ./mods/signal
You just have to edit main.ts
to load your submodule and route to it depending on wildcard DNS, URL path, HTTP headers, or anything you want.
Import your module
import * as Mainnet from "./mods/mainnet/mod.ts";
Choose a unique prefix for environment variables
const mainnet = await Mainnet.main("MAINNET_")
Choose how to route requests to it
const onHttpRequest = async (request: Request) => {
if (request.headers.get("host")?.startsWith("mainnet."))
return await mainnet.onHttpRequest(request)
return new Response("Not Found", { status: 404 })
}
If you're self-hosting, you can simply add a .env.local
file in the submodule directory.
If you're cloud-hosting, you can use environment variables but with a dedicated prefix.
e.g. PRIVATE_KEY_ZERO_HEX
becomes MAINNET_PRIVATE_KEY_ZERO_HEX
if the prefix is MAINNET_
git submodule foreach git pull origin main