Custom domain support

When you deploy an HTTP service on Unison Cloud, it is assigned a URL of the form https://my-username.unison-services.cloud/s/my-service/ where my-username is your Unison Cloud/Share username and my-service is the service name.

If you are on a paid Unison Cloud plan you can also expose services under your own custom domain in a few simple API calls.

For example, if you own my-excellent-domain.com, you can configure requests to my-excellent-domain.com (or my-subdomain.my-excellent-domain.com ) to be served as though they were issued to my-username.unison-services.cloud/s/my-service.

Setting up a custom domain

Below you will find step-by-step instructions.

For the impatient, this is a complete service deployment with a custom domain assignment:

domains.example : '{IO, Exception} ()
domains.example =
  myService : HttpRequest -> HttpResponse
  myService = cases
    HttpRequest GET _ (URI _ _ (Path ["hello"]) _ _) _ _ ->
      "hi!" |> Text.toUtf8 |> Body |> HttpResponse.ok
    _ -> HttpResponse.notFound
  Cloud.main do
    service = ServiceName.named "my-service"
    serviceHash = deployHttp Environment.default() myService
    unisonCloudUrl = ServiceName.assign service serviceHash
    myDomain = HostName "my-subdomain.my-excellent-domain.com"
    createDomainMapping myDomain (ServiceName.name service)

A DNS lookup after running this function might look something like this:

> dig +noall +answer my-subdomain.my-excellent-domain.com A
my-subdomain.my-excellent-domain.com      1526    IN      A       54.189.213.233

Step 1: Own a domain

Unison Cloud can't really help you here, but there are plenty of domain registrars who can, such as namecheap or porkbun.

Step 2: Deploy a service

Write your HTTP service and deploy it with deployHttp or deployHttpWebSocket.

Step 3: Assign a service name

Create a service name with ServiceName.named and then assign your service to it with ServiceName.assign.

See the HTTP service tutorial if you need a guide for service deployments.

Step 4: Configure the custom domain mapping

Call createDomainMapping to configure Unison Cloud to route requests for your domain to your service.

Step 5: Point your DNS to Unison Cloud

Use your DNS provider to add an A record that points your domain (or subdomain) to 54.189.213.233 , which is a stable IP address for Unison Cloud user services.

An example DNS record might look like the following:

> dig +noall +answer my-subdomain.my-excellent-domain.com A
my-subdomain.my-excellent-domain.com      1526    IN      A       54.189.213.233

For security, do not point a wildcard record such as *.my-excellent-domain.com to Unison Cloud. Create individual mappings for each subdomain that you wish to forward to Unison Cloud.

That's it! You can now make a request to your service at https://my-subdomain.my-excellent-domain.com 🚀