A cli tool to quickly create and manage nginx server blocks.
https://up.js.org
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.1 KiB
61 lines
1.1 KiB
// Module courtesy of TRGWII
|
|
// Original: https://github.com/trgwii/isFQDN
|
|
|
|
'use strict';
|
|
|
|
var fs = require('fs-extra');
|
|
|
|
// Official list of TLDs should be fetched from:
|
|
// https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
|
|
|
// You must have received a copy of the list along with `up`
|
|
// Run `npm run build` to update the cached list
|
|
|
|
function isFQDN(domain) {
|
|
|
|
// Importing and parsing `tlds.txt` file
|
|
var tlds = fs.readFileSync('./assets/tlds.txt', 'utf8')
|
|
.split(/[\r\n]+/)
|
|
.filter(x => !x.startsWith('#'));
|
|
|
|
if (domain.length > 253) {
|
|
return false;
|
|
}
|
|
|
|
var labels = domain.split('.').reverse();
|
|
|
|
if (labels.length < 2) {
|
|
return false;
|
|
}
|
|
|
|
var tld = labels[0];
|
|
|
|
if (!tlds.includes(tld.toUpperCase())) {
|
|
return false;
|
|
}
|
|
|
|
for (var label of labels) {
|
|
|
|
const len = label.length;
|
|
|
|
if (len > 63 || len === 0) {
|
|
return false;
|
|
}
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
|
const char = label[i];
|
|
|
|
if ((i === 0 || i === len - 1) && char === '-') {
|
|
return false;
|
|
}
|
|
|
|
if (!char.match(/^[a-zA-Z0-9-]$/)) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
module.exports = isFQDN;
|