A tiny, dead-simple gateway and reverse-proxy.
sgw issues a cookie with a random value to each device that visits the gateway. Once a device is approved by an admin, it's allowed through the gateway to the services behind it.
- An unknown device requests any route, sgw sets a cookie and responds with a holding page.
- The holding page polls sgw, which places the device on a waitlist.
- An admin reviews the waitlist at
/sgw/adminand may approve the device. - Once approved, the device's next poll succeeds and it is proxied through.
Build the binary:
go build
Create a config file (sgwconfig.json, read from the working directory):
{
"routes": [
{ "prefix": "/notes/", "destination": "http://localhost:8080" },
{ "prefix": "/media/", "destination": "http://localhost:8081" }
],
"tls": {
"domain": "gateway.example.com"
}
}routesarenet/httpServeMux patterns mapped to backend URLs.tls, when present, serves HTTPS on443with certificates obtained automatically from Let's Encrypt, and redirects HTTP to HTTPS. When absent, sgw serves plain HTTP on port7490for local use.
Finally:
./sgw serve
The first admin device is bootstrapped from the command line. Visit the gateway from a browser, copy the device hash shown on the holding page, and on the server (from sgw's working directory) run:
./sgw approve --admin <hash>
An admin device can then approve all subsequent devices from the dashboard at /sgw/admin.
- sgw reads
sgwconfig.jsonandstore.txt, and caches certificates incerts/, all relative to its working directory. - Let's Encrypt issuance requires the domain's A record to point at the host, and ports 80/443 to be reachable from the internet.
certs/andstore.txtare obviously worth backing up.