forked from engineering/cloudservices
fixes to cwg and catch
parent
f3668d06ab
commit
88a619134a
|
@ -95,6 +95,7 @@ export default class CWG extends Command {
|
|||
* @example await CWG.createDomain('mydomain.cloud.libraryofcode.org', 6781);
|
||||
*/
|
||||
public async createDomain(account: AccountInterface, domain: string, port: number, x509Certificate: { cert?: string, key?: string } = { cert: '/etc/nginx/ssl/cloud-org.chain.crt', key: '/etc/nginx/ssl/cloud-org.key.pem' }) {
|
||||
try {
|
||||
if (port <= 1024 || port >= 65535) throw new RangeError(`Port range must be between 1024 and 65535, received ${port}.`);
|
||||
if (await this.client.db.Domain.exists({ port })) throw new Error(`Port ${port} already exists in the database.`);
|
||||
if (await this.client.db.Domain.exists({ domain })) throw new Error(`Domain ${domain} already exists in the database.`);
|
||||
|
@ -116,13 +117,20 @@ export default class CWG extends Command {
|
|||
enabled: true,
|
||||
});
|
||||
if (domain.includes('cloud.libraryofcode.org')) {
|
||||
const dmn = domain.split('.');
|
||||
await axios({
|
||||
method: 'post',
|
||||
url: 'https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records',
|
||||
headers: { Authorization: `Bearer ${this.client.config.cloudflare}`, 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify({ type: 'CNAME', name: domain, content: 'cloud.libraryofcode.org', proxied: false }),
|
||||
data: JSON.stringify({ type: 'CNAME', name: `${dmn[0]}.${dmn[1]}`, content: 'cloud.libraryofcode.org', proxied: false }),
|
||||
});
|
||||
}
|
||||
return entry.save();
|
||||
} catch (error) {
|
||||
await fs.unlink(`/etc/nginx/sites-available/${domain}`);
|
||||
await fs.unlink(`/etc/nginx/sites-enabled/${domain}`);
|
||||
await this.client.db.Domain.deleteMany({ domain });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue