EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
seed_cloudflare_dns.js
Go to the documentation of this file.
1// Script to create missing Cloudflare DNS records for all tenants
2
3require('dotenv').config();
4const { createSubdomain } = require('../services/cloudflare');
5const pool = require('../services/db');
6
7/**
8 *
9 */
10async function seedCloudflareDNS() {
11 const target = 'demo.everydaytech.au';
12 const zoneName = process.env.ZONE_NAME || 'everydaytech.au';
13 const tenants = await pool.query('SELECT subdomain FROM tenants WHERE status = $1', ['active']);
14
15 for (const row of tenants.rows) {
16 const subdomain = row.subdomain;
17 const fqdn = `${subdomain}.${zoneName}`;
18 try {
19 console.log(`Creating DNS for: ${fqdn}`);
20 await createSubdomain(subdomain, target);
21 console.log(`✅ DNS created for ${fqdn}`);
22 } catch (err) {
23 if (err.code === 'SUBDOMAIN_EXISTS') {
24 console.log(`🔁 DNS already exists for ${fqdn}`);
25 } else {
26 console.error(`❌ Failed for ${fqdn}:`, err.message);
27 }
28 }
29 }
30 process.exit(0);
31}
32
33seedCloudflareDNS();