Hostnames, domains and protocols
Every project answers on one hostname: its subdomain on a domain. The domain is either one MockHub shares between all customers, such as mockhub.dev, or a custom domain your workspace owns.
Subdomains on a shared domain
Section titled “Subdomains on a shared domain”When you create a project you choose its Subdomain and its Host. The Host list shows the shared domains you can use and your workspace’s usable custom domains.
On a shared domain, MockHub adds a hyphen and six random characters to the subdomain you choose: with orders-api on mockhub.dev, the project answers at an address such as https://orders-api-k3x9p2.mockhub.dev. A name on a domain every customer shares could otherwise be claimed first, or made to look like another company’s. On your workspace’s custom domain the subdomain is used exactly as you type it. Choose a hostname lists when the characters are added.
- A subdomain is unique on its domain. The form tells you when one is taken, and the shortest subdomain your plan allows.
- Changing a project’s subdomain or host changes its address. Anything still calling the old address stops reaching the project.
- When a project gives up a subdomain on a shared domain, by taking another subdomain or domain or by being deleted, no other workspace can take that subdomain for 30 days. Your workspace can take it back at any time. Clients that still call the old address during that time reach nothing; after it, they may reach somebody else’s project, so update them.
Custom domains
Section titled “Custom domains”A custom domain lets your projects answer under a domain you own, such as orders.mocks.example.com. Custom domains belong to the workspace and are available on Pro and Team.
You add a domain in the workspace settings under Custom domains. Before any project can use it, it has to pass two independent checks, both shown on the domain’s row:
- Ownership (TXT record): a TXT record at
_mockhub-challenge.followed by your domain, holding the token MockHub shows you. It proves the domain is yours. - Traffic (wildcard CNAME record): a wildcard record, such as
*.mocks.example.com, pointing atmockhub.dev. It proves that requests for any project’s subdomain will reach MockHub. MockHub checks it by looking up a random name under your domain.
Nothing is ever served at the domain itself: a project’s hostname is always a subdomain of it. The certificate for each hostname is issued and renewed automatically.
The workspace settings also let you choose a default domain for new projects. Changing it does not move existing projects.
Which schemes a domain serves
Section titled “Which schemes a domain serves”Whether a hostname answers over HTTPS, HTTP or both is a setting of its domain, shared by every project on it:
| Setting | Effect |
|---|---|
| HTTPS only | The default. A plain http:// request is redirected to the same address over HTTPS. |
| HTTP and HTTPS | Both schemes answer. HTTP traffic is unencrypted. |
| HTTP only | Only plain HTTP answers. HTTPS connections are refused. Traffic is unencrypted. |
You change it for a custom domain under Protocols on its row in Settings → Custom domains. Shared domains have a fixed setting. Either way, the project form previews the addresses a project will answer on, with their schemes, before you create it.
A project’s page always shows the addresses it actually answers on. Use those rather than assuming https://.
HTTP and browsers
Section titled “HTTP and browsers”A page loaded over HTTPS cannot call an http:// address, whatever the mock’s CORS headers say: the browser blocks the request before it is sent. Allowing HTTP on a domain makes it available to other clients, not to such pages.
Some top-level domains, such as .dev and .app, are HTTPS-only in every major browser. A browser never sends plain HTTP to a domain under them, whatever the domain’s setting. MockHub warns you when you allow HTTP on such a domain.
Pages and cookies on a shared domain
Section titled “Pages and cookies on a shared domain”Every project on a shared domain such as mockhub.dev shares that domain with every other customer’s projects. So that no project can act as a web page on MockHub’s name, or set cookies its neighbours receive, the gateway holds every answer on a shared domain to three rules. A custom domain is yours, and its answers keep exactly what the mock sends.
- A page cannot run in a browser. Every answer carries
Content-Security-Policy: sandbox, added beside anyContent-Security-Policythe mock sends, which still applies. A browser that opens an HTML mock shows it, but runs none of its scripts, submits none of its forms and gives it no access to cookies or storage. Code that calls the mock, such asfetch, an SDK,curlor a test runner, ignores the header, so an API mock behaves exactly as without it, and CORS is unaffected. - A browser is not handed a download. A browser that opens an answer that is an attachment, or of a type browsers hand to their download manager, such as
application/octet-stream,application/zip, a font ortext/csv, gets Download blocked, a403, instead of the file. Plain text, HTML, CSS, JavaScript, JSON, XML, PDF and the common image, audio and video formats open as before; Download blocked lists the exact types. Every answer also carriesX-Content-Type-Options: nosniff, so a browser does not guess a different type. Code that fetches the same address, such asfetch, an SDK,curlor a test runner’s HTTP client, gets the file unchanged. - A cookie stays on the project’s hostname. A
Set-CookiewhoseDomainnames anything but the project’s own hostname, such asDomain=mockhub.dev, arrives without itsDomain, so the browser keeps the cookie for that hostname only. A cookie for the project’s own hostname, or without aDomain, arrives as the mock wrote it.
All three apply to answers forwarded from an upstream and to the gateway’s own answers too, such as the 404 when no mock matched or the 402 of a suspended workspace. A request log shows the response as the mock or upstream produced it, without them.
A page that has to run in a browser, such as a mocked sign-in or payment step that end-to-end tests drive, or a file a browser must download, belongs on a custom domain. There is no setting that turns the rules off on a shared domain.
Limits
Section titled “Limits”- A project whose subdomain on a verified custom domain is also defined elsewhere in your DNS, such as an
apirecord pointing at another server, verifies but never receives traffic. MockHub does not detect this. - An HTML page served from a shared domain never runs its scripts or forms in a browser, its cookies never reach another hostname, and a browser navigating to a download is refused. Use a custom domain for pages and downloads that must; see Pages and cookies on a shared domain.