notfound: better error message for IP

This commit is contained in:
Girish Ramakrishnan
2024-04-26 21:21:34 +02:00
parent 8a987db177
commit a783944700
2 changed files with 13 additions and 2 deletions
+12 -2
View File
@@ -51,9 +51,19 @@
<script type="text/javascript">
window.addEventListener('load', (event) => {
document.getElementById('message').innerHTML =
'You are seeing this page because the DNS record of <b>' + window.location.hostname + '</b> is set to this server\'s IP'
// https://stackoverflow.com/questions/37437890/check-if-url-has-domain-name-and-not-an-ip
const containsLetter = /[a-zA-z]/.test(window.location.hostname); // ignore technicality that IP can contain letters ! http://192.168.0x1.0x1 or http://0xc0.0xa8.1.1
const isIPv6 = location.hostname.startsWith('[') && location.hostname.endsWith(']');
let message;
if (!containsLetter || isIPv6) { // ipv4 or ipv6
message = 'You cannot view Cloudron dashboard by IP address. Instead, navigate to the domain you configured during setup i.e <b>https://my.domain.example</b> .'
+ '<br>If you do not remember your domain, SSH into your server and run <code>cloudron-support --owner-login</code> .'
} else { // hostname
message = 'You are seeing this page because the DNS record of <b>' + window.location.hostname + '</b> is set to this server\'s IP'
+ ' but Cloudron has no app configured for this domain.';
}
document.getElementById('message').innerHTML = message;
});
</script>
</head>