From 119b05c7347a6bec57a1cd467f386733742f39cd Mon Sep 17 00:00:00 2001 From: yaroslav8765 Date: Fri, 20 Feb 2026 14:14:18 +0200 Subject: [PATCH 1/2] fix: don't paste database url to the .env.local file of created application, if database url is not local --- adminforth/commands/createApp/utils.js | 47 +++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/adminforth/commands/createApp/utils.js b/adminforth/commands/createApp/utils.js index 6e13a84f1..736ac0c63 100644 --- a/adminforth/commands/createApp/utils.js +++ b/adminforth/commands/createApp/utils.js @@ -13,6 +13,9 @@ import Handlebars from 'handlebars'; import { promisify } from 'util'; import { getVersion } from '../cli.js'; +import { URL } from 'url' +import net from 'net' + const execAsync = promisify(exec); function detectAdminforthVersion() { @@ -159,6 +162,48 @@ function checkForExistingPackageJson(options) { } } +function checkIfDatabaseLocal(urlString) { + if (urlString.startsWith('sqlite')) { + return true; + } + try { + const url = new URL(urlString) + + const host = url.hostname + + if (!host) return false + + // localhost + if (host === 'localhost') return true + + // loopback ipv4 + if (host === '127.0.0.1') return true + + // loopback ipv6 + if (host === '::1') return true + + // private IP ranges + if (net.isIP(host)) { + if ( + host.startsWith('10.') || + host.startsWith('192.168.') || + host.match(/^172\.(1[6-9]|2\d|3[0-1])\./) + ) { + return true + } + } + + // docker / local network aliases + if (['db', 'postgres', 'mysql', 'mongo'].includes(host)) { + return true + } + + return false + } catch { + return false + } +} + async function scaffoldProject(ctx, options, cwd) { const projectDir = path.join(cwd, options.appName); await fse.ensureDir(projectDir); @@ -253,7 +298,7 @@ async function writeTemplateFiles(dirname, cwd, options) { { src: '.env.local.hbs', dest: '.env.local', - data: { dbUrl, prismaDbUrl }, + data: { dbUrl: checkIfDatabaseLocal(dbUrl) ? dbUrl : null, prismaDbUrl }, }, { src: '.env.prod.hbs', From 3fc7911d6142be4d8caa59a0b08c60e6d6978c08 Mon Sep 17 00:00:00 2001 From: yaroslav8765 Date: Fri, 20 Feb 2026 14:19:35 +0200 Subject: [PATCH 2/2] fix: fill .env file when we are creating adminforth app --- adminforth/commands/createApp/utils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adminforth/commands/createApp/utils.js b/adminforth/commands/createApp/utils.js index 736ac0c63..7abda8db1 100644 --- a/adminforth/commands/createApp/utils.js +++ b/adminforth/commands/createApp/utils.js @@ -314,8 +314,7 @@ async function writeTemplateFiles(dirname, cwd, options) { // We'll write .env using the same content as .env.sample src: '.env.local.hbs', dest: '.env', - data: {}, - empty: true, + data: {dbUrl, prismaDbUrl}, }, { src: 'adminuser.ts.hbs',