Attempt to provision subdomain on team create
This commit is contained in:
66
shared/utils/domains.js
Normal file
66
shared/utils/domains.js
Normal file
@@ -0,0 +1,66 @@
|
||||
// @flow
|
||||
import parseDomain from 'parse-domain';
|
||||
|
||||
export function stripSubdomain(hostname: string) {
|
||||
const parsed = parseDomain(hostname);
|
||||
if (!parsed) return hostname;
|
||||
|
||||
if (parsed.tld) return `${parsed.domain}.${parsed.tld}`;
|
||||
return parsed.domain;
|
||||
}
|
||||
|
||||
export const RESERVED_SUBDOMAINS = [
|
||||
'about',
|
||||
'account',
|
||||
'admin',
|
||||
'advertising',
|
||||
'api',
|
||||
'assets',
|
||||
'archive',
|
||||
'beta',
|
||||
'billing',
|
||||
'blog',
|
||||
'cache',
|
||||
'cdn',
|
||||
'code',
|
||||
'community',
|
||||
'dashboard',
|
||||
'developer',
|
||||
'developers',
|
||||
'forum',
|
||||
'help',
|
||||
'home',
|
||||
'http',
|
||||
'https',
|
||||
'imap',
|
||||
'localhost',
|
||||
'mail',
|
||||
'mobile',
|
||||
'news',
|
||||
'newsletter',
|
||||
'ns1',
|
||||
'ns2',
|
||||
'ns3',
|
||||
'ns4',
|
||||
'password',
|
||||
'profile',
|
||||
'sandbox',
|
||||
'script',
|
||||
'scripts',
|
||||
'setup',
|
||||
'signin',
|
||||
'signup',
|
||||
'smtp',
|
||||
'support',
|
||||
'status',
|
||||
'static',
|
||||
'stats',
|
||||
'test',
|
||||
'update',
|
||||
'updates',
|
||||
'www',
|
||||
'www1',
|
||||
'www2',
|
||||
'www3',
|
||||
'www4',
|
||||
];
|
||||
17
shared/utils/domains.test.js
Normal file
17
shared/utils/domains.test.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||
import { stripSubdomain } from './domains';
|
||||
|
||||
describe('#stripSubdomain', () => {
|
||||
test('to work with localhost', () => {
|
||||
expect(stripSubdomain('localhost')).toBe('localhost');
|
||||
});
|
||||
test('to return domains without a subdomain', () => {
|
||||
expect(stripSubdomain('example')).toBe('example');
|
||||
expect(stripSubdomain('example.com')).toBe('example.com');
|
||||
expect(stripSubdomain('example.org:3000')).toBe('example.org');
|
||||
});
|
||||
test('to remove subdomains', () => {
|
||||
expect(stripSubdomain('test.example.com')).toBe('example.com');
|
||||
expect(stripSubdomain('test.example.com:3000')).toBe('example.com');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user