Connecting Apex domain registered with AWS

Hi all,
Like many before me, I’m here with a question about connecting my apex domain to the Weweb app :smiley:
I have read all the posts I could find about this (including this and this) and I understand this is not currently a supported feature.

I understand there are some ways around this (e.g. Cloudflare, S3 bucket, CoAlias, etc.) but I had another idea in mind which should technically work but requires a tiny change from the Weweb’s side, and I was wondering if that would be possible.

For those of us who use AWS Route53 to manage their domain’s DNS, there is an option to point your apex domain as an “Alias” to another AWS resource, which can be in another AWS account. Now, if I’m not wrong, Weweb uses AWS Cloudfront to host the customer apps (hence the cloudfront .net CNAME you have to put on your subdomain).

That means, those of us who use Route53 can simply use the same Cloudfront address and point their apex domain to their app with an A record + AWS Alias. The only problem is the SSL certificate. The apex domain connects to the Weweb server, but the SSL certificate issued is only for the subdomain selected by the customer in the panel. If that certificate included the apex domain as an “Alternative domain” I suspect this would work just fine. (It’s technically not a 301 redirect, but it’s good enough :D)

So I was wondering if Weweb Team would consider adding this as an option? So in your custom domain tab in the settings, you can nominate one alternative domain to be included in the SSL certificate (with some conditions if necessary like “only if one domain is a subdomain of the other”).

Also keen to hear the community’s thoughts around this approach especially if there are any cons to it.

Thank you!

In the meantime, for anyone else using Route53 who wants to connect both their apex and www domains to their Weweb website, this is one easy way of achieving this:

  1. Make a Cloudfront distribution for your apex domain.
  2. Give it an SSL certificate that covers your apex domain (e.g. my-domain.com) and make sure to add the apex domain as an Alternate Domain to the distribution (even though this domain is likely your origin, it still needs to be an alternate domain). It should look like this:

  1. Make a Cloudfront Function that redirects all requests to the www subdomain. Here’s the code:
async function handler(event) {
    const request = event.request;
    const newurl = `https://www.your-domain.com` + request.uri;
  
    const response = {
        statusCode: 301,
        statusDescription: 'Moved Permanently',
        headers:
            { "location": { "value": newurl } }
    }

    return response;
}
  1. Back in your Cloudfront distribution, change the main behaviour (the one that covers all paths *) to use the function you made above in its “Viewer Request”.

It should now redirect all requests to the non-www domain to the www subdomain.