A staging site for a client, a draft of the new docs, an internal handbook: plenty of static sites should not be public, and a static site has no server of its own to check a password. The usual ways around that each cost something.
The usual ways, and their catch
- A login page in JavaScript. It hides the page from people who do not look, and from no one who does: the files are still served to anyone who asks for them, and the password is in the bundle.
- HTTP basic auth on your own server. It works, but it needs a server you run, its configuration and a password file, for a site that was meant to need neither.
- An unlisted address. A long random URL is not protection. It ends up in a chat, a browser history, a referrer header.
- Single sign-on in front of everything. Right for an internal tool, heavy for one page you want a client to see this week.
What a static site needs is the check done where the files are served, before any of them leaves.
How it works on Subnomic Sites
A site is public by default. On the site’s page you can switch it to one of two modes:
- Anyone with the password. One shared password, asked for once and remembered for 12 hours. For a client or a reviewer who has no account.
- Workspace members only. Visitors are sent to sign in and come straight back. Nobody outside the workspace gets in, and there is no password to leak or rotate.
The check happens on the server for every request, so nothing is served before it passes: not the HTML, not the scripts, not the images.
What else it covers
- Every preview. Protection belongs to the site, so each deployment’s preview address is behind the same password. A preview link you share for review is not a way around it.
- Caches and search engines. A protected page is never cached by anything in front of it and never indexed, whatever your
_headersfile says. - A mistake in the settings. If the protection is ever misconfigured, the site refuses visitors rather than going public.
Changing the password
Type a new one and save. Turning protection off keeps the password, so turning it back on later does not mean choosing a new one.
Setting it up
npm run build subnomic sites create client-preview --dir dist subnomic sites deploy --prod
Then open the site in the console and choose who may see it. Protection is on every plan, the free one included, which has one site with 1 GB of traffic a month. The rest is in the Sites documentation; how this compares with other static hosts’ free plans is in Free static site hosting compared.