Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
325 stars 56 forks source link

Migrating DNS from an existing service to Static Web Apps #1193

Open SSKLCP opened 1 year ago

SSKLCP commented 1 year ago

Hi there,

Not sure if this is a feature request or something that is missing in the documentation but I'm having trouble migrating an existing site to a Static Web App...

I have a site currently hosted on-prem which is websiteA.domain.com. The DNS is currently CNamed to our web server.

I want to move it to a Static Web App I have in Azure.

Unfortunately the two ways of verifying will cause some downtime as far as I can tell:

CNAME Verification I would need to re-point the CNAME from the existing web server to Azure, In the time between me making the change and Azure verifying the record (normally quick, sometimes not) people will get an error going to the site. TXT Verification I use Azure DNS and it doesn't support both a CNAME and TXT record pointing to the same subdomain, so I would need to remove the record entirely to do this, which is even less ideal than CNAME.

For things like App Services you can point a TXT record to asuid.websiteA.domain.com which would suit my needs but it doesn't seem to be a thing for SWA as far as I can see.

Is there an undocumented solution for this? If not, the feature request would be to add verification on a subdomain e.g. asuid.websiteA.domain.com so we can do smoother migrations from existing sites.

thomasgauvin commented 1 year ago

Hi @SSKLCP, for this use case, we have the possibility of adding a TXT record to the Static Web App, and then directing traffic with either a ALIAS, a CNAME or an A Record.

The TXT record is used for ownership validation, which can be done independently first. Then you can re-point your CNAME from your current website to your Static Web App to avoid any downtime. Hope this helps!

SSKLCP commented 1 year ago

Hi @thomasgauvin, I did cover this scenario above. In Azure DNS I can't setup both a TXT record and CNAME record to the same address. For example: websiteA.domain.com in our DNS currently has a CNAME record to websever1.domain.com If I try and add a TXT record for websiteA.domain.com I get the error in Azure:

Failed to create record set 'websiteA'. Error: The record could not be created because a CNAME record with the same name already exists in this zone. 

So I'm unable to create the TXT record for ownership without first removing the record which defeats the point a little.

thomasgauvin commented 1 year ago

Hi @SSKLCP, gotcha, I understand now.

We also support TXT validations with an alternative host/name _dnsauth.subdomain (instead of subdomain).

So, if you are adding a TXT record for custom domain subdomain.somedomain.com, and you already have a CNAME in your DNS with host/name subdomain, you can add a TXT record with host/name _dnsauth.subdomain.

Once this is done, you can change the value of your existing CNAME to direct the traffic to the Static Web App.

SSKLCP commented 1 year ago

@thomasgauvin, Perfect!

This is exactly what I wanted. I'll give that a test now.

However, please can this be represented in the documentation or even as a note when selecting TXT validation in the portal?

I scoured the internet to try and find a solution to this and there's no mention of it anywhere as far as I can see, so would be good to be made available to others with the same trouble.

thomasgauvin commented 1 year ago

Great to hear, please let us know if it worked out. Regarding docs, that's definitely something we can do, and improve the TXT record for custom subdomain documentation as well

SSKLCP commented 1 year ago

Yep, it worked as expected! Thanks @thomasgauvin

Cadey commented 11 months ago

On the app services, they have a way to do this also with "asuid". I wish this information was more readily available on the normal docs.

Please can you make a request showing this as a scenario to add domain names. @thomasgauvin ?