nstantpage-agent 0.5.16 → 0.5.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/start.js +5 -2
- package/dist/devServer.js +30 -0
- package/package.json +1 -1
package/dist/commands/start.js
CHANGED
|
@@ -25,7 +25,7 @@ import { TunnelClient } from '../tunnel.js';
|
|
|
25
25
|
import { LocalServer } from '../localServer.js';
|
|
26
26
|
import { PackageInstaller } from '../packageInstaller.js';
|
|
27
27
|
import { probeLocalPostgres, ensureLocalProjectDb, closeAdminPool, writeDatabaseUrlToEnv } from '../projectDb.js';
|
|
28
|
-
const VERSION = '0.5.
|
|
28
|
+
const VERSION = '0.5.17';
|
|
29
29
|
/**
|
|
30
30
|
* Resolve the backend API base URL.
|
|
31
31
|
* - If --backend is passed, use it
|
|
@@ -631,7 +631,6 @@ async function startAdditionalProject(projectId, opts) {
|
|
|
631
631
|
databaseUrl = await ensureLocalProjectDb(projectId);
|
|
632
632
|
if (databaseUrl) {
|
|
633
633
|
console.log(chalk.green(` ✓ Database ready: project_${projectId}`));
|
|
634
|
-
writeDatabaseUrlToEnv(projectDir, databaseUrl);
|
|
635
634
|
}
|
|
636
635
|
}
|
|
637
636
|
}
|
|
@@ -677,6 +676,10 @@ async function startAdditionalProject(projectId, opts) {
|
|
|
677
676
|
console.log(chalk.yellow(` ⚠ Could not fetch files: ${err.message}`));
|
|
678
677
|
progress('fetching-files', `Warning: ${err.message}`);
|
|
679
678
|
}
|
|
679
|
+
// Write DATABASE_URL to .env AFTER file fetch (so it doesn't get overwritten)
|
|
680
|
+
if (databaseUrl) {
|
|
681
|
+
writeDatabaseUrlToEnv(projectDir, databaseUrl);
|
|
682
|
+
}
|
|
680
683
|
// Wait for API server before proceeding (tunnel can keep connecting in background)
|
|
681
684
|
await apiServerPromise;
|
|
682
685
|
progress('starting-server', `API server ready`);
|
package/dist/devServer.js
CHANGED
|
@@ -9,6 +9,32 @@ import path from 'path';
|
|
|
9
9
|
import fs from 'fs';
|
|
10
10
|
import http from 'http';
|
|
11
11
|
import os from 'os';
|
|
12
|
+
/**
|
|
13
|
+
* Parse a .env file into a key-value map.
|
|
14
|
+
* Handles KEY=VALUE, KEY="VALUE", KEY='VALUE', comments (#), and empty lines.
|
|
15
|
+
*/
|
|
16
|
+
function parseDotenv(filePath) {
|
|
17
|
+
if (!fs.existsSync(filePath))
|
|
18
|
+
return {};
|
|
19
|
+
const result = {};
|
|
20
|
+
const lines = fs.readFileSync(filePath, 'utf-8').split('\n');
|
|
21
|
+
for (const line of lines) {
|
|
22
|
+
const trimmed = line.trim();
|
|
23
|
+
if (!trimmed || trimmed.startsWith('#'))
|
|
24
|
+
continue;
|
|
25
|
+
const eqIdx = trimmed.indexOf('=');
|
|
26
|
+
if (eqIdx === -1)
|
|
27
|
+
continue;
|
|
28
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
29
|
+
let val = trimmed.slice(eqIdx + 1).trim();
|
|
30
|
+
// Strip surrounding quotes
|
|
31
|
+
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
32
|
+
val = val.slice(1, -1);
|
|
33
|
+
}
|
|
34
|
+
result[key] = val;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
12
38
|
export class DevServer {
|
|
13
39
|
options;
|
|
14
40
|
process = null;
|
|
@@ -39,6 +65,8 @@ export class DevServer {
|
|
|
39
65
|
}
|
|
40
66
|
const { projectDir, port } = this.options;
|
|
41
67
|
const extraEnv = this.options.env || {};
|
|
68
|
+
// Load .env file from project root (lower priority than explicit env vars)
|
|
69
|
+
const dotenvVars = parseDotenv(path.join(projectDir, '.env'));
|
|
42
70
|
// Detect project type
|
|
43
71
|
const pkgPath = path.join(projectDir, 'package.json');
|
|
44
72
|
if (!fs.existsSync(pkgPath)) {
|
|
@@ -63,6 +91,7 @@ export class DevServer {
|
|
|
63
91
|
cwd: projectDir,
|
|
64
92
|
env: {
|
|
65
93
|
...process.env,
|
|
94
|
+
...dotenvVars,
|
|
66
95
|
...extraEnv,
|
|
67
96
|
PORT: String(backendPort),
|
|
68
97
|
SERVER_PORT: String(backendPort),
|
|
@@ -97,6 +126,7 @@ export class DevServer {
|
|
|
97
126
|
}
|
|
98
127
|
const frontendEnv = {
|
|
99
128
|
...process.env,
|
|
129
|
+
...dotenvVars,
|
|
100
130
|
...extraEnv,
|
|
101
131
|
PORT: String(port),
|
|
102
132
|
};
|
package/package.json
CHANGED