@fecommunity/reactpress-server 1.0.0-beta.13 → 1.0.0-beta.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.
@@ -11,6 +11,31 @@ const { spawn } = require('child_process');
11
11
  const PORT = 3003;
12
12
  const SERVER_PORT = 3002;
13
13
 
14
+ // Load and set environment variables from .env file
15
+ function loadEnvVariables(envPath) {
16
+ try {
17
+ const envContent = fs.readFileSync(envPath, 'utf8');
18
+ const envLines = envContent.split('\n');
19
+
20
+ envLines.forEach(line => {
21
+ const trimmedLine = line.trim();
22
+ if (trimmedLine && !trimmedLine.startsWith('#')) {
23
+ const [key, ...valueParts] = trimmedLine.split('=');
24
+ if (key && valueParts.length > 0) {
25
+ const value = valueParts.join('=').trim();
26
+ process.env[key.trim()] = value;
27
+ }
28
+ }
29
+ });
30
+
31
+ console.log(chalk.cyan(`📝 Environment variables loaded from .env`));
32
+ return true;
33
+ } catch (error) {
34
+ console.log(chalk.yellow('⚠️ Could not load .env file:', error.message));
35
+ return false;
36
+ }
37
+ }
38
+
14
39
  // Main entry point with auto-detection
15
40
  async function main() {
16
41
  const args = process.argv.slice(2);
@@ -26,6 +51,8 @@ async function main() {
26
51
  await runInstallationWizard();
27
52
  } else {
28
53
  console.log(chalk.green('✅ Configuration found. Starting server...'));
54
+ // Load environment variables from .env file
55
+ loadEnvVariables(envPath);
29
56
  startServer();
30
57
  }
31
58
  }
@@ -58,9 +85,7 @@ async function runInstallationWizard() {
58
85
  port: parseInt(port),
59
86
  user: user.trim(),
60
87
  password: password,
61
- connectTimeout: 5000,
62
- acquireTimeout: 5000,
63
- timeout: 5000
88
+ connectTimeout: 5000
64
89
  });
65
90
 
66
91
  try {
@@ -149,6 +174,9 @@ SERVER_SITE_URL=${site.serverUrl}
149
174
  fs.writeFileSync(envPath, env);
150
175
  console.log(chalk.green('✅ Configuration saved to .env file'));
151
176
 
177
+ // Load the environment variables immediately
178
+ loadEnvVariables(envPath);
179
+
152
180
  res.json({
153
181
  success: true,
154
182
  message: 'ReactPress installed successfully! Starting server...',
@@ -193,11 +221,54 @@ function startServer() {
193
221
 
194
222
  // Start the NestJS server
195
223
  const serverDir = path.dirname(__dirname); // server directory
196
- const server = spawn('npm', ['run', 'dev'], {
197
- cwd: serverDir,
198
- stdio: 'inherit',
199
- env: { ...process.env, NODE_ENV: 'development' }
200
- });
224
+
225
+ // Check if we're in development or installed package
226
+ const isDevMode = fs.existsSync(path.join(serverDir, 'src'));
227
+
228
+ let server;
229
+ if (isDevMode) {
230
+ // Development mode - try different nest commands
231
+ const nestCommands = [
232
+ ['npx', ['nest', 'start', '--watch']],
233
+ ['npm', ['run', 'dev']],
234
+ ['node', ['node_modules/.bin/nest', 'start', '--watch']]
235
+ ];
236
+
237
+ let commandFound = false;
238
+ for (const [cmd, args] of nestCommands) {
239
+ try {
240
+ server = spawn(cmd, args, {
241
+ cwd: serverDir,
242
+ stdio: 'inherit',
243
+ env: { ...process.env, NODE_ENV: 'development' }
244
+ });
245
+ commandFound = true;
246
+ break;
247
+ } catch (error) {
248
+ console.log(chalk.yellow(`⚠️ ${cmd} not available, trying next option...`));
249
+ continue;
250
+ }
251
+ }
252
+
253
+ if (!commandFound) {
254
+ console.log(chalk.red('❌ Could not start development server. Please install @nestjs/cli globally:'));
255
+ console.log(chalk.cyan('npm install -g @nestjs/cli'));
256
+ return;
257
+ }
258
+ } else {
259
+ // Production mode - use built files
260
+ const mainPath = path.join(serverDir, 'dist', 'main.js');
261
+ if (fs.existsSync(mainPath)) {
262
+ server = spawn('node', [mainPath], {
263
+ cwd: serverDir,
264
+ stdio: 'inherit',
265
+ env: { ...process.env, NODE_ENV: 'production' }
266
+ });
267
+ } else {
268
+ console.log(chalk.red('❌ Server files not found. Please ensure the package is properly installed.'));
269
+ return;
270
+ }
271
+ }
201
272
 
202
273
  server.on('error', (error) => {
203
274
  console.log(chalk.red('❌ Failed to start server:'), error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fecommunity/reactpress-server",
3
- "version": "1.0.0-beta.13",
3
+ "version": "1.0.0-beta.17",
4
4
  "description": "ReactPress Server - NestJS-based backend API for ReactPress CMS",
5
5
  "author": "fecommunity",
6
6
  "license": "MIT",
@@ -98,10 +98,10 @@
98
98
  "typeorm": "^0.2.22",
99
99
  "ua-parser-js": "^0.7.28",
100
100
  "open": "^8.2.1",
101
- "express": "^4.18.2"
101
+ "express": "^4.18.2",
102
+ "@nestjs/cli": "^6.9.0"
102
103
  },
103
104
  "devDependencies": {
104
- "@nestjs/cli": "^6.9.0",
105
105
  "@nestjs/schematics": "^6.7.0",
106
106
  "@nestjs/testing": "^6.7.1",
107
107
  "@types/express": "4.17.18",