@fecommunity/reactpress-server 1.0.0-beta.17 → 1.0.0-beta.20
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/main.d.ts +5 -0
- package/dist/main.js +326 -39
- package/dist/main.js.map +1 -1
- package/dist/public/index.html +439 -0
- package/dist/starter.d.ts +1 -0
- package/dist/starter.js +101 -0
- package/dist/starter.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +534 -8
- package/package.json +1 -4
- package/public/index.html +439 -0
- package/bin/reactpress-server.js +0 -697
package/bin/reactpress-server.js
DELETED
|
@@ -1,697 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const express = require('express');
|
|
4
|
-
const mysql = require('mysql2/promise');
|
|
5
|
-
const chalk = require('chalk');
|
|
6
|
-
const open = require('open');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const { spawn } = require('child_process');
|
|
10
|
-
|
|
11
|
-
const PORT = 3003;
|
|
12
|
-
const SERVER_PORT = 3002;
|
|
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
|
-
|
|
39
|
-
// Main entry point with auto-detection
|
|
40
|
-
async function main() {
|
|
41
|
-
const args = process.argv.slice(2);
|
|
42
|
-
|
|
43
|
-
// Check if .env exists in current directory
|
|
44
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
45
|
-
const hasEnv = fs.existsSync(envPath);
|
|
46
|
-
|
|
47
|
-
console.log(chalk.blue('🚀 ReactPress Server'));
|
|
48
|
-
|
|
49
|
-
if (!hasEnv) {
|
|
50
|
-
console.log(chalk.yellow('⚠️ No configuration found. Starting installation wizard...'));
|
|
51
|
-
await runInstallationWizard();
|
|
52
|
-
} else {
|
|
53
|
-
console.log(chalk.green('✅ Configuration found. Starting server...'));
|
|
54
|
-
// Load environment variables from .env file
|
|
55
|
-
loadEnvVariables(envPath);
|
|
56
|
-
startServer();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Installation wizard
|
|
61
|
-
async function runInstallationWizard() {
|
|
62
|
-
console.log(chalk.cyan('🌍 Starting installation wizard...'));
|
|
63
|
-
|
|
64
|
-
const app = express();
|
|
65
|
-
app.use(express.json());
|
|
66
|
-
app.use(express.urlencoded({ extended: true }));
|
|
67
|
-
app.get('/', (req, res) => res.send(getWordPressHTML()));
|
|
68
|
-
|
|
69
|
-
// Test database connection
|
|
70
|
-
app.post('/test-db', async (req, res) => {
|
|
71
|
-
const { host, port, user, password, database } = req.body;
|
|
72
|
-
|
|
73
|
-
if (!host || !port || !user || !database) {
|
|
74
|
-
return res.json({
|
|
75
|
-
success: false,
|
|
76
|
-
message: 'All database fields are required.'
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
console.log(chalk.cyan(`Testing connection to ${user}@${host}:${port}/${database}...`));
|
|
82
|
-
|
|
83
|
-
const conn = await mysql.createConnection({
|
|
84
|
-
host: host.trim(),
|
|
85
|
-
port: parseInt(port),
|
|
86
|
-
user: user.trim(),
|
|
87
|
-
password: password,
|
|
88
|
-
connectTimeout: 5000
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
await conn.query(`USE \`${database.trim()}\``);
|
|
93
|
-
console.log(chalk.green(`Database '${database}' exists and accessible`));
|
|
94
|
-
} catch (dbError) {
|
|
95
|
-
if (dbError.code === 'ER_BAD_DB_ERROR') {
|
|
96
|
-
await conn.query(`CREATE DATABASE \`${database.trim()}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`);
|
|
97
|
-
console.log(chalk.green(`Database '${database}' created successfully`));
|
|
98
|
-
} else {
|
|
99
|
-
throw dbError;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
await conn.end();
|
|
104
|
-
console.log(chalk.green('✅ Database connection test passed'));
|
|
105
|
-
|
|
106
|
-
res.json({
|
|
107
|
-
success: true,
|
|
108
|
-
message: `Successfully connected to database '${database}' on ${host}:${port}`
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.log(chalk.red('❌ Database connection failed:'), error.message);
|
|
113
|
-
|
|
114
|
-
let errorMessage = 'Database connection failed: ';
|
|
115
|
-
|
|
116
|
-
switch (error.code) {
|
|
117
|
-
case 'ECONNREFUSED':
|
|
118
|
-
errorMessage += `Cannot connect to MySQL server at ${host}:${port}. Please ensure MySQL is running.`;
|
|
119
|
-
break;
|
|
120
|
-
case 'ER_ACCESS_DENIED_ERROR':
|
|
121
|
-
errorMessage += `Access denied for user '${user}'. Please check your username and password.`;
|
|
122
|
-
break;
|
|
123
|
-
case 'ENOTFOUND':
|
|
124
|
-
errorMessage += `Host '${host}' not found. Please check the hostname.`;
|
|
125
|
-
break;
|
|
126
|
-
case 'ETIMEDOUT':
|
|
127
|
-
errorMessage += `Connection timeout to ${host}:${port}. Please check your network and firewall settings.`;
|
|
128
|
-
break;
|
|
129
|
-
case 'ER_BAD_DB_ERROR':
|
|
130
|
-
errorMessage += `Database '${database}' does not exist and cannot be created. Please check your permissions.`;
|
|
131
|
-
break;
|
|
132
|
-
default:
|
|
133
|
-
errorMessage += error.message;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
res.json({ success: false, message: errorMessage });
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// Install and start server
|
|
141
|
-
app.post('/install', async (req, res) => {
|
|
142
|
-
const { db, site } = req.body;
|
|
143
|
-
|
|
144
|
-
// Final validation
|
|
145
|
-
try {
|
|
146
|
-
const testConn = await mysql.createConnection({
|
|
147
|
-
host: db.host.trim(),
|
|
148
|
-
port: parseInt(db.port),
|
|
149
|
-
user: db.user.trim(),
|
|
150
|
-
password: db.password,
|
|
151
|
-
database: db.database.trim()
|
|
152
|
-
});
|
|
153
|
-
await testConn.end();
|
|
154
|
-
} catch (error) {
|
|
155
|
-
return res.json({
|
|
156
|
-
success: false,
|
|
157
|
-
message: 'Final database validation failed. Please test your connection again.'
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const env = `# ReactPress Configuration
|
|
162
|
-
# Generated on ${new Date().toISOString()}
|
|
163
|
-
|
|
164
|
-
DB_HOST=${db.host}
|
|
165
|
-
DB_PORT=${db.port}
|
|
166
|
-
DB_USER=${db.user}
|
|
167
|
-
DB_PASSWD=${db.password}
|
|
168
|
-
DB_DATABASE=${db.database}
|
|
169
|
-
CLIENT_SITE_URL=${site.clientUrl}
|
|
170
|
-
SERVER_SITE_URL=${site.serverUrl}
|
|
171
|
-
`;
|
|
172
|
-
|
|
173
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
174
|
-
fs.writeFileSync(envPath, env);
|
|
175
|
-
console.log(chalk.green('✅ Configuration saved to .env file'));
|
|
176
|
-
|
|
177
|
-
// Load the environment variables immediately
|
|
178
|
-
loadEnvVariables(envPath);
|
|
179
|
-
|
|
180
|
-
res.json({
|
|
181
|
-
success: true,
|
|
182
|
-
message: 'ReactPress installed successfully! Starting server...',
|
|
183
|
-
serverUrl: site.serverUrl
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Close installation server and start ReactPress server
|
|
187
|
-
setTimeout(() => {
|
|
188
|
-
console.log(chalk.green('\n🎉 Installation completed!'));
|
|
189
|
-
console.log(chalk.cyan('🚀 Starting ReactPress Server...'));
|
|
190
|
-
server.close();
|
|
191
|
-
startServer();
|
|
192
|
-
}, 2000);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
const server = app.listen(PORT, () => {
|
|
196
|
-
const url = `http://localhost:${PORT}`;
|
|
197
|
-
console.log(chalk.green(`✅ Installation wizard: ${url}`));
|
|
198
|
-
open(url);
|
|
199
|
-
console.log(chalk.gray('Press Ctrl+C to cancel\n'));
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
process.on('SIGINT', () => {
|
|
203
|
-
console.log(chalk.yellow('\n⚠️ Installation cancelled'));
|
|
204
|
-
server.close();
|
|
205
|
-
process.exit(0);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Start ReactPress server
|
|
210
|
-
function startServer() {
|
|
211
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
212
|
-
|
|
213
|
-
if (!fs.existsSync(envPath)) {
|
|
214
|
-
console.log(chalk.red('❌ No configuration found!'));
|
|
215
|
-
console.log(chalk.yellow('Please run the installation first.'));
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
console.log(chalk.blue('🚀 Starting ReactPress Server...'));
|
|
220
|
-
console.log(chalk.cyan(`🌍 Server will be available at: http://localhost:${SERVER_PORT}/api`));
|
|
221
|
-
|
|
222
|
-
// Start the NestJS server
|
|
223
|
-
const serverDir = path.dirname(__dirname); // server directory
|
|
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
|
-
}
|
|
272
|
-
|
|
273
|
-
server.on('error', (error) => {
|
|
274
|
-
console.log(chalk.red('❌ Failed to start server:'), error.message);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// Open browser after server starts
|
|
278
|
-
setTimeout(() => {
|
|
279
|
-
open(`http://localhost:${SERVER_PORT}/api`);
|
|
280
|
-
}, 5000);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// WordPress-style HTML
|
|
284
|
-
function getWordPressHTML() {
|
|
285
|
-
return `<!DOCTYPE html>
|
|
286
|
-
<html lang="en">
|
|
287
|
-
<head>
|
|
288
|
-
<meta charset="UTF-8">
|
|
289
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
290
|
-
<title>ReactPress › Installation</title>
|
|
291
|
-
<style>
|
|
292
|
-
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
293
|
-
body {
|
|
294
|
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
295
|
-
background: #f1f1f1;
|
|
296
|
-
color: #444;
|
|
297
|
-
line-height: 1.4;
|
|
298
|
-
}
|
|
299
|
-
.wp-container {
|
|
300
|
-
max-width: 600px;
|
|
301
|
-
margin: 40px auto;
|
|
302
|
-
background: #fff;
|
|
303
|
-
border: 1px solid #ccd0d4;
|
|
304
|
-
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
|
|
305
|
-
}
|
|
306
|
-
.wp-header {
|
|
307
|
-
background: #0073aa;
|
|
308
|
-
color: #fff;
|
|
309
|
-
padding: 24px;
|
|
310
|
-
text-align: center;
|
|
311
|
-
border-bottom: 1px solid #005a87;
|
|
312
|
-
}
|
|
313
|
-
.wp-header h1 { font-size: 24px; font-weight: 400; margin-bottom: 8px; }
|
|
314
|
-
.wp-header p { font-size: 16px; opacity: 0.9; }
|
|
315
|
-
.wp-content { padding: 24px; }
|
|
316
|
-
.wp-step { display: none; }
|
|
317
|
-
.wp-step.active { display: block; }
|
|
318
|
-
.wp-step h2 { font-size: 22px; font-weight: 600; margin-bottom: 20px; color: #1d2327; }
|
|
319
|
-
.wp-description {
|
|
320
|
-
background: #f0f6fc;
|
|
321
|
-
border: 1px solid #c3e4f0;
|
|
322
|
-
border-left: 4px solid #0073aa;
|
|
323
|
-
padding: 12px 16px;
|
|
324
|
-
margin-bottom: 20px;
|
|
325
|
-
font-size: 14px;
|
|
326
|
-
color: #0c4a6e;
|
|
327
|
-
}
|
|
328
|
-
.wp-form-table { width: 100%; margin-bottom: 20px; }
|
|
329
|
-
.wp-form-table th {
|
|
330
|
-
text-align: left;
|
|
331
|
-
padding: 10px 0;
|
|
332
|
-
width: 140px;
|
|
333
|
-
vertical-align: top;
|
|
334
|
-
font-weight: 600;
|
|
335
|
-
color: #1d2327;
|
|
336
|
-
}
|
|
337
|
-
.wp-form-table td { padding: 10px 0; }
|
|
338
|
-
.wp-form-table input[type="text"],
|
|
339
|
-
.wp-form-table input[type="password"],
|
|
340
|
-
.wp-form-table input[type="number"],
|
|
341
|
-
.wp-form-table input[type="url"] {
|
|
342
|
-
width: 100%;
|
|
343
|
-
max-width: 320px;
|
|
344
|
-
padding: 8px 12px;
|
|
345
|
-
border: 1px solid #8c8f94;
|
|
346
|
-
border-radius: 4px;
|
|
347
|
-
font-size: 14px;
|
|
348
|
-
line-height: 1.4;
|
|
349
|
-
transition: border-color 0.15s ease-in-out;
|
|
350
|
-
}
|
|
351
|
-
.wp-form-table input:focus {
|
|
352
|
-
border-color: #0073aa;
|
|
353
|
-
outline: 0;
|
|
354
|
-
box-shadow: 0 0 0 1px #0073aa;
|
|
355
|
-
}
|
|
356
|
-
.wp-form-table .description {
|
|
357
|
-
font-size: 13px;
|
|
358
|
-
color: #646970;
|
|
359
|
-
margin-top: 4px;
|
|
360
|
-
}
|
|
361
|
-
.wp-button {
|
|
362
|
-
background: #0073aa;
|
|
363
|
-
color: #fff;
|
|
364
|
-
border: 1px solid #0073aa;
|
|
365
|
-
padding: 8px 16px;
|
|
366
|
-
font-size: 14px;
|
|
367
|
-
font-weight: 600;
|
|
368
|
-
border-radius: 3px;
|
|
369
|
-
cursor: pointer;
|
|
370
|
-
transition: all 0.15s ease-in-out;
|
|
371
|
-
text-decoration: none;
|
|
372
|
-
display: inline-block;
|
|
373
|
-
}
|
|
374
|
-
.wp-button:hover { background: #005a87; border-color: #005a87; }
|
|
375
|
-
.wp-button:disabled {
|
|
376
|
-
background: #f0f0f1;
|
|
377
|
-
border-color: #dcdcde;
|
|
378
|
-
color: #a7aaad;
|
|
379
|
-
cursor: not-allowed;
|
|
380
|
-
}
|
|
381
|
-
.wp-button.button-large { padding: 12px 24px; font-size: 16px; }
|
|
382
|
-
.wp-notice {
|
|
383
|
-
border: 1px solid #c3c4c7;
|
|
384
|
-
border-left-width: 4px;
|
|
385
|
-
padding: 12px;
|
|
386
|
-
margin: 16px 0;
|
|
387
|
-
background: #fff;
|
|
388
|
-
}
|
|
389
|
-
.wp-notice.notice-success { border-left-color: #00a32a; background: #f7fcf7; }
|
|
390
|
-
.wp-notice.notice-error { border-left-color: #d63638; background: #fcf2f2; }
|
|
391
|
-
.wp-notice p { margin: 0; font-size: 14px; }
|
|
392
|
-
.wp-progress { background: #f0f0f1; height: 4px; margin-bottom: 20px; }
|
|
393
|
-
.wp-progress-bar { background: #0073aa; height: 100%; transition: width 0.3s ease; }
|
|
394
|
-
.wp-loader {
|
|
395
|
-
display: inline-block;
|
|
396
|
-
width: 16px;
|
|
397
|
-
height: 16px;
|
|
398
|
-
border: 2px solid #f3f3f3;
|
|
399
|
-
border-top: 2px solid #0073aa;
|
|
400
|
-
border-radius: 50%;
|
|
401
|
-
animation: wp-spin 1s linear infinite;
|
|
402
|
-
margin-right: 8px;
|
|
403
|
-
}
|
|
404
|
-
@keyframes wp-spin {
|
|
405
|
-
0% { transform: rotate(0deg); }
|
|
406
|
-
100% { transform: rotate(360deg); }
|
|
407
|
-
}
|
|
408
|
-
.wp-footer {
|
|
409
|
-
background: #f6f7f7;
|
|
410
|
-
border-top: 1px solid #c3c4c7;
|
|
411
|
-
padding: 16px 24px;
|
|
412
|
-
text-align: center;
|
|
413
|
-
font-size: 13px;
|
|
414
|
-
color: #646970;
|
|
415
|
-
}
|
|
416
|
-
.text-center { text-align: center; }
|
|
417
|
-
</style>
|
|
418
|
-
</head>
|
|
419
|
-
<body>
|
|
420
|
-
<div class="wp-container">
|
|
421
|
-
<div class="wp-header">
|
|
422
|
-
<h1>ReactPress</h1>
|
|
423
|
-
<p>5-Minute Installation</p>
|
|
424
|
-
</div>
|
|
425
|
-
|
|
426
|
-
<div class="wp-progress">
|
|
427
|
-
<div class="wp-progress-bar" id="progressBar" style="width: 33%;"></div>
|
|
428
|
-
</div>
|
|
429
|
-
|
|
430
|
-
<div class="wp-content">
|
|
431
|
-
<!-- Step 1: Database Configuration -->
|
|
432
|
-
<div class="wp-step active" id="step1">
|
|
433
|
-
<h2>Database Connection Information</h2>
|
|
434
|
-
|
|
435
|
-
<div class="wp-description">
|
|
436
|
-
You should have this information available from your web hosting provider. If you don't have it, contact them before continuing.
|
|
437
|
-
</div>
|
|
438
|
-
|
|
439
|
-
<table class="wp-form-table">
|
|
440
|
-
<tr>
|
|
441
|
-
<th><label for="dbHost">Database Host</label></th>
|
|
442
|
-
<td>
|
|
443
|
-
<input type="text" id="dbHost" value="127.0.0.1" />
|
|
444
|
-
<p class="description">Usually "localhost" or "127.0.0.1"</p>
|
|
445
|
-
</td>
|
|
446
|
-
</tr>
|
|
447
|
-
<tr>
|
|
448
|
-
<th><label for="dbPort">Database Port</label></th>
|
|
449
|
-
<td>
|
|
450
|
-
<input type="number" id="dbPort" value="3306" />
|
|
451
|
-
<p class="description">Default MySQL port is 3306</p>
|
|
452
|
-
</td>
|
|
453
|
-
</tr>
|
|
454
|
-
<tr>
|
|
455
|
-
<th><label for="dbUser">Username</label></th>
|
|
456
|
-
<td>
|
|
457
|
-
<input type="text" id="dbUser" value="" placeholder="Database username" />
|
|
458
|
-
<p class="description">Your MySQL username</p>
|
|
459
|
-
</td>
|
|
460
|
-
</tr>
|
|
461
|
-
<tr>
|
|
462
|
-
<th><label for="dbPassword">Password</label></th>
|
|
463
|
-
<td>
|
|
464
|
-
<input type="password" id="dbPassword" value="" placeholder="Database password" />
|
|
465
|
-
<p class="description">Your MySQL password</p>
|
|
466
|
-
</td>
|
|
467
|
-
</tr>
|
|
468
|
-
<tr>
|
|
469
|
-
<th><label for="dbName">Database Name</label></th>
|
|
470
|
-
<td>
|
|
471
|
-
<input type="text" id="dbName" value="reactpress" />
|
|
472
|
-
<p class="description">The name of the database you want to use with ReactPress</p>
|
|
473
|
-
</td>
|
|
474
|
-
</tr>
|
|
475
|
-
</table>
|
|
476
|
-
|
|
477
|
-
<div id="dbResult"></div>
|
|
478
|
-
|
|
479
|
-
<p class="text-center">
|
|
480
|
-
<button class="wp-button button-large" onclick="testDatabase()" id="testBtn">
|
|
481
|
-
Test Database Connection
|
|
482
|
-
</button>
|
|
483
|
-
</p>
|
|
484
|
-
</div>
|
|
485
|
-
|
|
486
|
-
<!-- Step 2: Site Configuration -->
|
|
487
|
-
<div class="wp-step" id="step2">
|
|
488
|
-
<h2>Site Information</h2>
|
|
489
|
-
|
|
490
|
-
<div class="wp-description">
|
|
491
|
-
Please provide the following information. Don't worry, you can always change these settings later.
|
|
492
|
-
</div>
|
|
493
|
-
|
|
494
|
-
<table class="wp-form-table">
|
|
495
|
-
<tr>
|
|
496
|
-
<th><label for="clientUrl">Client Site URL</label></th>
|
|
497
|
-
<td>
|
|
498
|
-
<input type="url" id="clientUrl" value="http://localhost:3001" />
|
|
499
|
-
<p class="description">The URL where your ReactPress frontend will be accessible</p>
|
|
500
|
-
</td>
|
|
501
|
-
</tr>
|
|
502
|
-
<tr>
|
|
503
|
-
<th><label for="serverUrl">API Server URL</label></th>
|
|
504
|
-
<td>
|
|
505
|
-
<input type="url" id="serverUrl" value="http://localhost:3002" />
|
|
506
|
-
<p class="description">The URL where your ReactPress API server will run</p>
|
|
507
|
-
</td>
|
|
508
|
-
</tr>
|
|
509
|
-
</table>
|
|
510
|
-
|
|
511
|
-
<div id="installResult"></div>
|
|
512
|
-
|
|
513
|
-
<p class="text-center">
|
|
514
|
-
<button class="wp-button button-large" onclick="installReactPress()" id="installBtn">
|
|
515
|
-
Install & Start ReactPress
|
|
516
|
-
</button>
|
|
517
|
-
</p>
|
|
518
|
-
</div>
|
|
519
|
-
|
|
520
|
-
<!-- Step 3: Success -->
|
|
521
|
-
<div class="wp-step" id="step3">
|
|
522
|
-
<h2>🎉 Installation Complete!</h2>
|
|
523
|
-
|
|
524
|
-
<div class="wp-notice notice-success">
|
|
525
|
-
<p><strong>ReactPress has been installed and is starting...</strong></p>
|
|
526
|
-
</div>
|
|
527
|
-
|
|
528
|
-
<p>Your ReactPress server is now starting up. You can:</p>
|
|
529
|
-
|
|
530
|
-
<ul style="margin: 16px 0 16px 20px;">
|
|
531
|
-
<li>Close this browser window</li>
|
|
532
|
-
<li>The server API will open automatically at <strong>http://localhost:3002/api</strong></li>
|
|
533
|
-
<li>Access your admin panel at <strong>http://localhost:3001/admin</strong> (when client is running)</li>
|
|
534
|
-
</ul>
|
|
535
|
-
|
|
536
|
-
<div class="wp-description">
|
|
537
|
-
<strong>Note:</strong> To restart the server in the future, simply run <code>npx @fecommunity/reactpress-server</code> again.
|
|
538
|
-
</div>
|
|
539
|
-
</div>
|
|
540
|
-
</div>
|
|
541
|
-
|
|
542
|
-
<div class="wp-footer">
|
|
543
|
-
<p>Need help? <a href="https://github.com/fecommunity/reactpress/issues" target="_blank">ReactPress Documentation</a></p>
|
|
544
|
-
</div>
|
|
545
|
-
</div>
|
|
546
|
-
|
|
547
|
-
<script>
|
|
548
|
-
let currentStep = 1;
|
|
549
|
-
const totalSteps = 3;
|
|
550
|
-
let isTestingConnection = false;
|
|
551
|
-
|
|
552
|
-
function updateProgress() {
|
|
553
|
-
const progress = (currentStep / totalSteps) * 100;
|
|
554
|
-
document.getElementById('progressBar').style.width = progress + '%';
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
function showStep(step) {
|
|
558
|
-
document.querySelectorAll('.wp-step').forEach(s => s.classList.remove('active'));
|
|
559
|
-
document.getElementById('step' + step).classList.add('active');
|
|
560
|
-
currentStep = step;
|
|
561
|
-
updateProgress();
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
function showNotice(message, type = 'error', containerId = 'dbResult') {
|
|
565
|
-
const container = document.getElementById(containerId);
|
|
566
|
-
container.innerHTML = \`
|
|
567
|
-
<div class="wp-notice notice-\${type}">
|
|
568
|
-
<p>\${message}</p>
|
|
569
|
-
</div>
|
|
570
|
-
\`;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
function validateDatabaseInputs() {
|
|
574
|
-
const host = document.getElementById('dbHost').value.trim();
|
|
575
|
-
const port = document.getElementById('dbPort').value.trim();
|
|
576
|
-
const user = document.getElementById('dbUser').value.trim();
|
|
577
|
-
const password = document.getElementById('dbPassword').value;
|
|
578
|
-
const database = document.getElementById('dbName').value.trim();
|
|
579
|
-
|
|
580
|
-
if (!host || !port || !user || !database) {
|
|
581
|
-
showNotice('Please fill in all required fields.', 'error');
|
|
582
|
-
return false;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
if (isNaN(port) || port < 1 || port > 65535) {
|
|
586
|
-
showNotice('Please enter a valid port number (1-65535).', 'error');
|
|
587
|
-
return false;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
return { host, port, user, password, database };
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
async function testDatabase() {
|
|
594
|
-
if (isTestingConnection) return;
|
|
595
|
-
|
|
596
|
-
const dbData = validateDatabaseInputs();
|
|
597
|
-
if (!dbData) return;
|
|
598
|
-
|
|
599
|
-
isTestingConnection = true;
|
|
600
|
-
const testBtn = document.getElementById('testBtn');
|
|
601
|
-
const originalText = testBtn.innerHTML;
|
|
602
|
-
|
|
603
|
-
testBtn.disabled = true;
|
|
604
|
-
testBtn.innerHTML = '<span class="wp-loader"></span>Testing connection...';
|
|
605
|
-
|
|
606
|
-
try {
|
|
607
|
-
const response = await fetch('/test-db', {
|
|
608
|
-
method: 'POST',
|
|
609
|
-
headers: { 'Content-Type': 'application/json' },
|
|
610
|
-
body: JSON.stringify(dbData)
|
|
611
|
-
});
|
|
612
|
-
|
|
613
|
-
const result = await response.json();
|
|
614
|
-
|
|
615
|
-
if (result.success) {
|
|
616
|
-
showNotice(result.message, 'success');
|
|
617
|
-
setTimeout(() => {
|
|
618
|
-
showStep(2);
|
|
619
|
-
}, 1500);
|
|
620
|
-
} else {
|
|
621
|
-
showNotice(result.message, 'error');
|
|
622
|
-
}
|
|
623
|
-
} catch (error) {
|
|
624
|
-
showNotice('Failed to connect to server. Please try again.', 'error');
|
|
625
|
-
} finally {
|
|
626
|
-
isTestingConnection = false;
|
|
627
|
-
testBtn.disabled = false;
|
|
628
|
-
testBtn.innerHTML = originalText;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
async function installReactPress() {
|
|
633
|
-
const dbData = validateDatabaseInputs();
|
|
634
|
-
if (!dbData) {
|
|
635
|
-
showStep(1);
|
|
636
|
-
return;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
const clientUrl = document.getElementById('clientUrl').value.trim();
|
|
640
|
-
const serverUrl = document.getElementById('serverUrl').value.trim();
|
|
641
|
-
|
|
642
|
-
if (!clientUrl || !serverUrl) {
|
|
643
|
-
showNotice('Please fill in all site URLs.', 'error', 'installResult');
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
const installBtn = document.getElementById('installBtn');
|
|
648
|
-
const originalText = installBtn.innerHTML;
|
|
649
|
-
|
|
650
|
-
installBtn.disabled = true;
|
|
651
|
-
installBtn.innerHTML = '<span class="wp-loader"></span>Installing & Starting...';
|
|
652
|
-
|
|
653
|
-
try {
|
|
654
|
-
const response = await fetch('/install', {
|
|
655
|
-
method: 'POST',
|
|
656
|
-
headers: { 'Content-Type': 'application/json' },
|
|
657
|
-
body: JSON.stringify({
|
|
658
|
-
db: dbData,
|
|
659
|
-
site: { clientUrl, serverUrl }
|
|
660
|
-
})
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
const result = await response.json();
|
|
664
|
-
|
|
665
|
-
if (result.success) {
|
|
666
|
-
showStep(3);
|
|
667
|
-
// Auto-close and redirect to server after a delay
|
|
668
|
-
setTimeout(() => {
|
|
669
|
-
if (result.serverUrl) {
|
|
670
|
-
window.open(result.serverUrl + '/api', '_blank');
|
|
671
|
-
}
|
|
672
|
-
}, 3000);
|
|
673
|
-
} else {
|
|
674
|
-
showNotice(result.message, 'error', 'installResult');
|
|
675
|
-
}
|
|
676
|
-
} catch (error) {
|
|
677
|
-
showNotice('Installation failed. Please try again.', 'error', 'installResult');
|
|
678
|
-
} finally {
|
|
679
|
-
installBtn.disabled = false;
|
|
680
|
-
installBtn.innerHTML = originalText;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
// Initialize
|
|
685
|
-
updateProgress();
|
|
686
|
-
document.getElementById('dbHost').focus();
|
|
687
|
-
</script>
|
|
688
|
-
</body>
|
|
689
|
-
</html>`;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
// Run the main function
|
|
693
|
-
if (require.main === module) {
|
|
694
|
-
main().catch(console.error);
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
module.exports = { main, startServer };
|