@@ -13,6 +13,9 @@ import Handlebars from 'handlebars';
1313import { promisify } from 'util' ;
1414import { getVersion } from '../cli.js' ;
1515
16+ import { URL } from 'url'
17+ import net from 'net'
18+
1619const execAsync = promisify ( exec ) ;
1720
1821function detectAdminforthVersion ( ) {
@@ -159,6 +162,44 @@ function checkForExistingPackageJson(options) {
159162 }
160163}
161164
165+ function checkIfDatabaseLocal ( urlString ) {
166+ if ( urlString . startsWith ( 'sqlite' ) ) {
167+ return true ;
168+ }
169+ try {
170+ const url = new URL ( urlString )
171+
172+ const host = url . hostname
173+
174+ if ( ! host ) return false
175+
176+ // localhost
177+ if ( host === 'localhost' ) return true
178+
179+ // loopback ipv4
180+ if ( host === '127.0.0.1' ) return true
181+
182+ // loopback ipv6
183+ if ( host === '::1' ) return true
184+
185+ // private IP ranges
186+ if ( net . isIP ( host ) ) {
187+ if (
188+ host . startsWith ( '10.' ) ||
189+ host . startsWith ( '192.168.' ) ||
190+ host . match ( / ^ 1 7 2 \. ( 1 [ 6 - 9 ] | 2 \d | 3 [ 0 - 1 ] ) \. / )
191+ ) {
192+ return true
193+ }
194+ }
195+
196+
197+ return false
198+ } catch {
199+ return false
200+ }
201+ }
202+
162203async function scaffoldProject ( ctx , options , cwd ) {
163204 const projectDir = path . join ( cwd , options . appName ) ;
164205 await fse . ensureDir ( projectDir ) ;
@@ -253,7 +294,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
253294 {
254295 src : '.env.local.hbs' ,
255296 dest : '.env.local' ,
256- data : { dbUrl, prismaDbUrl } ,
297+ data : { dbUrl : checkIfDatabaseLocal ( dbUrl ) ? dbUrl : null , prismaDbUrl } ,
257298 } ,
258299 {
259300 src : '.env.prod.hbs' ,
@@ -269,8 +310,7 @@ async function writeTemplateFiles(dirname, cwd, options) {
269310 // We'll write .env using the same content as .env.sample
270311 src : '.env.local.hbs' ,
271312 dest : '.env' ,
272- data : { } ,
273- empty : true ,
313+ data : { dbUrl, prismaDbUrl} ,
274314 } ,
275315 {
276316 src : 'adminuser.ts.hbs' ,
0 commit comments