I think about a decade ago pow did something similar, but using the .test domain, and perhaps ruby specific
https://github.com/basecamp/pow/tree/master