Subdomains, Site Mode & Hosting
OcaltQL gives you direct programmatic control over your ocalt.site subdomains and live site hosting - all from within a script running in your namespace.
SUBDOMAIN
SUBDOMAIN ADD registers a new subdomain under your namespace. SUBDOMAIN REMOVE deregisters one. SUBDOMAIN LIST returns every subdomain you own. SUBDOMAIN SEARCH filters that list. SUBDOMAIN INFO tells you where one of them is served from.
SUBDOMAIN ADD "mysite" SET ?result
AFTER EMIT ?result
(* ?result("success") = true, ?result("subdomain") = "mysite", ?result("url") = "https://mysite.ocalt.site" *)
(* Fails with an error if the subdomain is under 5 characters, contains anything other than letters/numbers/hyphens, is already registered to another account, or your tier's subdomain limit is reached *)
SUBDOMAIN ADD "mysite" AT "/mounted/mysite" SET ?result
AFTER EMIT ?result("path")
(* AT places the subdomain's folder anywhere under /root or /mounted.
Omit it entirely and the folder is created at /root/sites/mysite *)
One Subdomain, One Folder
Every subdomain is served from exactly one folder, and that folder is decided when the name is registered. Registering a name you already own again does not create a second site:
- With
AT, the new path replaces the old one. The subdomain is served from the new folder from that moment, and the previous folder stops being its site. Nothing in the previous folder is moved or deleted - it simply becomes an ordinary folder again. - Without
AT, nothing changes. The subdomain keeps the folder it already has, and?result("unchanged")istrue.
SUBDOMAIN ADD "mysite" AT "/root/projects/mysite-v2" SET ?result
AFTER SUBDOMAIN INFO "mysite" SET ?site
AFTER EMIT ?site("path")
(* "/root/projects/mysite-v2" - the only folder mysite is served from *)
Registering a folder also places the two push-notification files, sw.js and ocalt-push.js, in it. A folder that already has a file of either name keeps its own; it is never overwritten.
SUBDOMAIN ADD "shop" ON "tld.com" AT "/mounted/shop" SET ?result
AFTER EMIT ?result("url")
(* Serves at https://shop.tld.com from /mounted/shop *)
AFTER SUBDOMAIN ADD "docs" ON "tld.com" SET ?result2
AFTER EMIT ?result2("url")
(* Serves at https://docs.tld.com from /root/sites/tld.com/docs *)
ON scopes the registration to a domain you already own here. The domain must have been pointed with DOMAIN first - registering a subdomain of a domain that is not yours, or not yet pointed, is an error. If the domain uses Ocalt's nameservers, nothing else is needed: Ocalt answers for the new name the moment it is registered. If you kept your own DNS, the name also needs an A record at 41.61.20.37 there; ?result("dns") says whether it already reaches Ocalt and, if not, gives the exact record to add. Without ON, the subdomain is on ocalt.site exactly as before.| Form | Serves at | From |
|---|---|---|
SUBDOMAIN ADD "mysite" | mysite.ocalt.site | /root/sites/mysite |
SUBDOMAIN ADD "mysite" AT "/mounted/mysite" | mysite.ocalt.site | /mounted/mysite |
SUBDOMAIN ADD "docs" ON "tld.com" | docs.tld.com | /root/sites/tld.com/docs |
SUBDOMAIN ADD "shop" ON "tld.com" AT "/mounted/shop" | shop.tld.com | /mounted/shop |
SUBDOMAIN ADD "devbox" TO "https://x.tunnel.ocalt.com" | devbox.ocalt.site | Forwarded to that URL |
SUBDOMAIN ADD "myapi1" TO ADDRESS "api.internal" | myapi1.ocalt.site | A process, site or folder on your namespace network |
Names Inside Names, and Wildcards
On a domain of your own, the name in front of it can have more than one level. "api.blog" on "tld.com" is api.blog.tld.com, a site of its own with its own folder. It does not depend on blog.tld.com existing; each name is registered by itself.
A * as the first level is a wildcard. "*" answers for every name directly under the domain that has no registration of its own, and "*.blog" does the same one level down, under blog.tld.com. A name you register by itself always wins over a wildcard, so shop.tld.com keeps serving its own folder next to "*".
SUBDOMAIN ADD "api.blog" ON "tld.com" SET ?api
AFTER EMIT ?api("url")
(* https://api.blog.tld.com, from /root/sites/tld.com/api.blog *)
AFTER SUBDOMAIN ADD "*" ON "tld.com" AT "/root/sites/catch-all" SET ?any
AFTER EMIT ?any("host")
(* *.tld.com: every name under tld.com that is not registered by itself *)
AFTER SUBDOMAIN ADD "*.blog" ON "tld.com" SET ?posts
(* anything.blog.tld.com, from /root/sites/tld.com/_any.blog *)
dns1.ocalt.com and dns2.ocalt.com answer for the domain can Ocalt answer for every name under it, and prove that to get one certificate that covers them all. On a domain that keeps its own DNS, a wildcard is refused with that reason; register each name you use by itself instead, and add an A record for each. Ordinary names, at any depth, work either way.SUBDOMAIN LIST ON "tld.com" SET ?names
AFTER FOREACH ?names SET ?n
OPEN
SUBDOMAIN INFO ?n ON "tld.com" SET ?i
AFTER EMIT ?i("host") & " serves " & ?i("path") & " (certificate: " & ?i("ssl") & ")"
CLOSE
AFTER SUBDOMAIN REMOVE "api.blog" ON "tld.com" SET ?gone
SUBDOMAIN LIST ON returns the names, as they were registered ("docs", "api.blog", "*"). SUBDOMAIN INFO ... ON returns subdomain, domain, host, path, url (null for a wildcard), target_kind, target, wildcard, ssl (pending, active or retry) and dns. TO and TO ADDRESS work with ON exactly as they do on ocalt.site. Removing a domain with DOMAIN REMOVE removes the names under it too.
/external is not a site root. An external binding lasts for one script execution, but a site is served on every later request - so a folder under /external has nothing to resolve against by the time a visitor arrives. Keep the files local and sync them instead: FILE SELECTION ?sel COPY TO "/root/sites/tld.com/media" on a CRON. The site then serves at local-disk speed with no stored remote credential.AT takes a path under /root or /mounted - the same two locations documented on Namespace Storage, and the same modifier APPLICATE uses to name an already-live site folder. Without AT, the default is unchanged: /root/sites/{subdomain}.TO - Forwarding Instead of a Folder
A subdomain serves a folder unless it is given something else to serve. TO forwards every request to a URL: the path and query string are joined onto it, the method, body, headers and cookies go with it, and whatever answers is what the visitor sees. The visitor stays on your subdomain the whole time. This is how a tunnel, a folder served off a machine with SERVE FOLDER, or a site hosted anywhere else gets a name of yours.
DIRECTIVE "laptop" TUNNEL PORT 3000 SET ?t
AFTER SUBDOMAIN ADD "devbox" TO ?t("url") SET ?s
AFTER EMIT ?s("url")
(* https://devbox.ocalt.site now answers with whatever runs on the laptop's port 3000 *)
DIRECTIVE "nas" SERVE FOLDER "/srv/www" SET ?src
AFTER SUBDOMAIN ADD "nasweb" TO ?src("url") SET ?s
TO ADDRESS points the subdomain at something on your namespace network, by its name or its address, with a port when it needs one. A mapped process is reached on its own port and answers the visitor directly; a mapped site or folder is served as though it were this subdomain's own folder. Nothing on the namespace network is reachable from the internet any other way, so this is a decision to publish that one thing, and only over HTTPS on this name.
WEBASSEMBLY SERVE "api" TYPE "node" ENTER "/root/app/server.js" ON 3000 SET ?p
AFTER NETWORK MAP "api.internal" TO PROCESS "api" SET ?m
AFTER SUBDOMAIN ADD "myapi1" TO ADDRESS "api.internal" SET ?s
(* or TO ADDRESS "10.0.0.2:3000" *)
Registering the name again with AT puts it back on a folder, and again with TO re-points it. SUBDOMAIN INFO reports which it is in target_kind - "folder", "url" or "address" - and the URL or address in target. A domain pointed at the subdomain serves the same thing.
*.tunnel.ocalt.com, serve.ocalt.com and other *.ocalt.site sites - are allowed, which is what makes the examples above work. To reach your own namespace, use TO ADDRESS. When a target is refused, a name that SUBDOMAIN ADD was registering for the first time is not left behind half-made: the call errors and the name stays free. A name you already had keeps its previous target.SUBDOMAIN REMOVE "mysite" SET ?result
AFTER EMIT ?result
(* Fails with an error if the subdomain does not exist, or does not belong to you *)
SUBDOMAIN LIST SET ?subs
AFTER FOREACH ?subs SET ?sub
OPEN
EMIT ?sub
CLOSE
SUBDOMAIN SEARCH "my" SET ?results
AFTER EMIT ?results
(* Returns only your own subdomains matching the search text *)
SUBDOMAIN INFO
A subdomain's folder is not always /root/sites/<name>: AT can place it anywhere in your namespace, so the name alone does not say where the site lives. SUBDOMAIN INFO answers from the same record the site router serves from, which makes it the one reliable way to find the folder a visitor is actually being served.
SUBDOMAIN INFO "mysite" SET ?site
AFTER EMIT ?site("path")
(* ?site("subdomain") = "mysite"
?site("path") = the folder it is served from, e.g. "/root/sites/mysite"
?site("domain") = "ocalt.site"
?site("url") = "https://mysite.ocalt.site" *)
It fails with Subdomain not found. for a name that is not registered, and with Not your subdomain. for one registered to another account.
SUBDOMAIN LIST SET ?subs
AFTER FOREACH ?subs SET ?sub
OPEN
SUBDOMAIN INFO ?sub SET ?site
AFTER EMIT ?site("url") & " <- " & ?site("path")
CLOSE
Namespace Path
Registering a subdomain creates a real directory at:
/root/sites/{subdomain}/
Every file placed inside this directory becomes reachable at https://{subdomain}.ocalt.site/, following the routing model below.
Routing Model
An incoming request path is resolved in strict priority order:
- Directory wins. If the path resolves to a real directory, its index file is used. Indexes are considered in a fixed order:
index.oql,index.php,index.py,index.js,index.rb,index.pl,index.sh,index.java,index.rs,index.go, and finallyindex.html. - Exact file match. If the literal path (with its real extension) exists as a file, it is served directly.
- Extensionless fallback. If no exact file exists at the literal path, extensions are tried in the same fixed order:
.oql,.php,.py,.js,.rb,.pl,.sh,.java,.rs,.go, and finally.html. A page is therefore addressed by name alone, independently of the language it is written in. - Otherwise, the request 404s.
(* /root/sites/mysite/about/index.oql *)
(* Reachable at https://mysite.ocalt.site/about/ - directory wins *)
(* /root/sites/mysite/contact.oql *)
(* Reachable at https://mysite.ocalt.site/contact - extensionless fallback *)
(* /root/sites/mysite/contact.html *)
(* Also reachable at https://mysite.ocalt.site/contact.html - exact match, always available regardless of the fallback *)
Site Mode Execution
A matched .oql file has its full text executed against the standard OcaltQL API, authenticated internally as the site's owner. Every page view is one real query against the owner's daily quota.
EMIT "<h1>Welcome</h1><p>Powered by OcaltQL.</p>"
Pages in Other Languages
A page need not be written in OcaltQL. Ten languages are executable in Site Mode, selected by file extension:
- Interpreted.
.oql,.php,.py,.js,.rb,.pland.sh. - Compiled on request.
.java,.rsand.goare built and executed as part of serving the page; the first request after a change therefore carries the compilation cost.
Execution is identical in every case. The file is handed to OcaltQL and run inside WebAssembly: one sandbox per request, within the owner’s namespace and against the owner’s daily quota. The host system is not reachable from the sandbox, and a page that fails affects nothing beyond its own request.
The request is supplied to the sandbox as a grant named request, a JSON object containing method, path, query, ip, host and agent, together with the structured members get, post, cookie, server and body. In PHP the familiar superglobals are reconstructed from it, so $_GET, $_POST, $_COOKIE, $_SERVER and $_REQUEST behave as expected. In the remaining languages the grant is read from the environment as OQL_request. Whatever the page writes to standard output constitutes the response; if that output begins with header lines followed by a blank line, those headers are sent with it.
<?php
echo "<h1>Hello from PHP</h1>";
echo "<p>Requested path: " . htmlspecialchars($_SERVER["REQUEST_URI"]) . "</p>";
import os, json
request = json.loads(os.environ["OQL_request"])
print("Content-Type: text/plain")
print()
print("method:", request["method"], "from", request["ip"])
https://mysite.ocalt.site/report, without its extension, exactly as an .oql page is. The language a page is written in is not visible to the visitor.package main
import (
"encoding/json"
"fmt"
"os"
)
func main() {
var request map[string]interface{}
json.Unmarshal([]byte(os.Getenv("OQL_request")), &request)
fmt.Printf("<h1>Status</h1><p>Method: %v</p>", request["method"])
}
session_start() therefore behaves conventionally: a value written to $_SESSION on one request is readable on the next. Session data is stored inside the site directory and is not reachable over the web, and because the identifier originates solely from the visitor’s cookie, one visitor cannot be served another’s session.<?php
session_start();
$_SESSION["seen"] = ($_SESSION["seen"] ?? 0) + 1;
echo "You have been here {$_SESSION["seen"]} times.";
!REQUEST, !GET, !POST and !COOKIE read the actual visitor's request, not an empty one. Site Mode is the path that supplies that context; the plain credentialed API carries none of it unless the caller opts in, as documented on API Reference.Static Files
Any file that is not .oql is served directly with its correct content type. Supported types include:
| Category | Extensions |
|---|---|
| Markup / code / text | html, htm, css, js, mjs, json, xml, txt, csv, md |
| Images | png, jpg, jpeg, gif, svg, ico, webp, bmp, avif, tif, tiff |
| Video | mp4, webm, mov, avi, mkv, ogv |
| Audio | mp3, wav, ogg, flac, aac, m4a |
| Documents | pdf, doc, docx, xls, xlsx, ppt, pptx, rtf, odt, zip |
| Fonts | woff, woff2, ttf, otf, eot |
(* /root/sites/mysite/logo.png - served directly as image/png *)
(* /root/sites/mysite/demo.mp4 - served directly as video/mp4 *)
(* /root/sites/mysite/embed.html - served as text/html, embeddable in an iframe *)
Custom Domains
There are two ways to point a domain at Ocalt, and the choice decides what you can do with it afterwards.
Option 1 - An A record, keeping your own DNS
At whoever provides your DNS, create an A record for the domain pointing at 41.61.20.37. For the apex that is a record on @; for www a second A record, or a CNAME to the apex.
You keep full control of the zone, so anything you already run on the domain stays exactly where it is. Ocalt sees only the traffic that arrives.
Mail is not a reason to choose this route. NEW EMAIL ACCOUNT gives you real mailboxes on the domain either way - under delegation Ocalt writes the records itself; on an A record you add one MX pointing at Ocalt and everything else follows. See IMAP & POP3.
The cost is that every subdomain you want served has to be created by you, at your provider, one record at a time. SUBDOMAIN ADD "shop" ON "tld.com" tells Ocalt which folder to serve, but nothing resolves until an A record for shop.tld.com exists in your zone. A wildcard * record pointing at 41.61.20.37 solves it in one line if your provider allows one.
Option 2 - Delegation to Ocalt’s nameservers
At your registrar, set the domain’s nameservers to dns1.ocalt.com and dns2.ocalt.com. Ocalt then serves the entire zone.
Save the domain first in Fabric (Domains > Add domain) so dns1 and dns2 already answer for it; the wizard then waits for the change and finishes by itself. Both nameservers share one address, which a few registries refuse; use Option 1 for those.
The zone is created with a wildcard, so every subdomain of the domain resolves immediately - shop.tld.com, docs.tld.com, anything you name later. SUBDOMAIN ADD ... ON is the only step, and there is no second system to keep in sync. Certificates are issued for the whole domain rather than one host at a time, because Ocalt can answer the DNS challenge itself.
Mail is handled for you. NEW EMAIL ACCOUNT "hello" AT "tld.com" WITH PASSWORD "..." creates a real mailbox on the delegated domain, and Ocalt writes the MX and authentication records the moment it exists - nothing to configure, nothing to point anywhere. The mailbox is then managed from OcaltQL with the IMAP and POP3 verbs like any other, or from any mail client.
DOMAIN "tld.com" TO "mysite.ocalt.site" SET ?var
AFTER NEW EMAIL ACCOUNT "hello" AT "tld.com" WITH PASSWORD "Password" SET ?acc
AFTER EMIT ?acc("address")
AFTER NEW EMAIL IMAP ?acc("imap_host") WITH "Password" AS ?acc("address") SET ?conn
AFTER EMAIL ?conn INBOX SET ?inbox
AFTER COUNT ?inbox SET ?n
AFTER EMIT ?n & " messages in hello@tld.com"
| A record | Delegation | |
|---|---|---|
| What you change | One record at your DNS provider | Nameservers at your registrar |
| New subdomains | You add each record, or one wildcard | Automatic - every subdomain resolves |
| Mail on the domain | One MX record pointing at Ocalt, added by you | Automatic - NEW EMAIL ACCOUNT writes the records |
| Arbitrary custom records | Yours, unchanged | Not editable by hand |
| Certificates | Per host, as each is pointed | Whole domain, including subdomains |
| Propagation | Minutes to an hour | Up to 48 hours |
DOMAIN checks before it accepts. Whichever route you take, DOMAIN "tld.com" TO ... resolves the domain and confirms it actually arrives at Ocalt before registering it. A domain whose DNS has not propagated yet, or points somewhere else, comes back with ?var("status") false and the reason in ?var("message") - retry once propagation completes.DOMAIN "tld.com" TO "mysite.ocalt.site" serves your site at the bare domain. Subdomains of it are then separate registrations with SUBDOMAIN ADD ... ON "tld.com", each with its own folder - they do not inherit the apex’s files.A domain you already own can be pointed at one of your ocalt.site subdomains - or at a tunnel token subdomain - from a script, with DOMAIN. Point the domain's DNS at Ocalt first; DOMAIN then registers it, reports whether the DNS actually resolves to Ocalt, and issues a certificate.
DOMAIN "tld.com" TO "subdomain.ocalt.site" SET ?var
AFTER IF ?var("status") IS EQUAL TO true
OPEN
EMIT "pointed"
CLOSE
OR
OPEN
EMIT ?var("message")
CLOSE
?var("status") is false when the domain's DNS does not resolve to Ocalt's server address, or when the domain is already claimed by another namespace. ?var("message") says which - the two failures are reported distinctly, not as one generic error.DOMAIN STATUS "tld.com" SET ?status
AFTER EMIT ?status("status")
AFTER EMIT ?status("message")
DOMAIN SSL "tld.com" SET ?ssl
AFTER SWITCH ?ssl("status")
OPEN
CASE "already in progress"
EMIT "certificate is being issued, check back shortly"
AFTER BREAK
CASE "successful - certificate is live"
EMIT "https is live on tld.com"
AFTER BREAK
CASE "failed try again"
EMIT "issuance failed - confirm DNS still points to Ocalt, then retry"
AFTER BREAK
CLOSE
DIRECTIVE "home-nas" TUNNEL PORT 3000 SET ?tunnel
AFTER DOMAIN "tld.com" TO ?tunnel("url") SET ?var
AFTER EMIT ?var("message")
(* The same verb points a domain at a tunnel token subdomain as at an ocalt.site subdomain *)
| Verb | Returns |
|---|---|
DOMAIN "tld.com" TO "subdomain.ocalt.site" SET ?var | Object - status true/false, message |
DOMAIN STATUS "tld.com" SET ?status | Object - current pointing state and reason; ?status("mail") is the mail checklist |
DOMAIN SSL "tld.com" SET ?ssl | ?ssl("status") - already in progress | failed try again | successful - certificate is live |
Namespace Isolation
Site Mode scripts execute inside the site owner's own namespace - the same /root and /mounted filesystem access already available to that account's regular OcaltQL scripts.