localdomain.js
1 #!/usr/bin/env node 2 const updateDotEnv = require("update-dotenv") 3 4 const arg = process.argv.slice(2)[0] 5 const isEnable = arg === "enable" 6 7 let domain = process.argv.slice(2)[1] 8 if (!domain) { 9 domain = "local.com" 10 } 11 12 const getAccountPortalUrl = () => { 13 if (isEnable) { 14 return `http://account.${domain}:10001` 15 } else { 16 return `http://localhost:10001` 17 } 18 } 19 20 const getBudibaseUrl = () => { 21 if (isEnable) { 22 return `http://${domain}:10000` 23 } else { 24 return `http://localhost:10000` 25 } 26 } 27 28 const getCookieDomain = () => { 29 if (isEnable) { 30 return `.${domain}` 31 } else { 32 return "" 33 } 34 } 35 36 /** 37 * For testing multi tenancy sub domains locally. 38 * 39 * Relies on an entry in /etc/hosts e.g: 40 * 41 * 127.0.0.1 local.com 42 * 43 * and an entry for each tenant you wish to test locally e.g: 44 * 45 * 127.0.0.1 t1.local.com 46 * 127.0.0.1 t2.local.com 47 */ 48 updateDotEnv({ 49 ACCOUNT_PORTAL_URL: getAccountPortalUrl(), 50 COOKIE_DOMAIN: getCookieDomain(), 51 PLATFORM_URL: getBudibaseUrl(), 52 }).then(() => console.log("Updated server!"))