Skip to content

Commit 8130cd9

Browse files
authored
Merge pull request #484 from devforth/feature/AdminForth/715/we-should-nto-probably-paste-u
Feature/admin forth/715/we should nto probably paste u
2 parents 4a74e4a + dd81bd6 commit 8130cd9

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

adminforth/commands/createApp/utils.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import Handlebars from 'handlebars';
1313
import { promisify } from 'util';
1414
import { getVersion } from '../cli.js';
1515

16+
import { URL } from 'url'
17+
import net from 'net'
18+
1619
const execAsync = promisify(exec);
1720

1821
function 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(/^172\.(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+
162203
async 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

Comments
 (0)