I am hosting an app that let’s say is available at domain.com and I want to automatically redirect sub domains not defined by other apps to domain.com. I’ve already set up the CNAME records to do this, and have added *.domain.com as a custom domain along with domain.com to my app.
The best solution available to you today is to do the redirect on your site itself, either server-side with an HTTP temporary redirect or permanent redirect, or client-side with a window.location redirect. If you detect that the host domain is a subdomain, your code can then do the redirect.