@fecommunity/reactpress-server 1.0.0-beta.3 → 1.0.0-beta.4
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/bin/reactpress-server.js +34 -90
- package/package.json +1 -1
package/bin/reactpress-server.js
CHANGED
|
@@ -42,93 +42,35 @@ program
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
//
|
|
46
|
-
console.log(chalk.cyan('📋
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
type: 'input',
|
|
63
|
-
name: 'DB_USERNAME',
|
|
64
|
-
message: 'Database username:',
|
|
65
|
-
default: 'root'
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
type: 'password',
|
|
69
|
-
name: 'DB_PASSWORD',
|
|
70
|
-
message: 'Database password:',
|
|
71
|
-
mask: '*'
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
type: 'input',
|
|
75
|
-
name: 'DB_DATABASE',
|
|
76
|
-
message: 'Database name:',
|
|
77
|
-
default: 'reactpress'
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
type: 'input',
|
|
81
|
-
name: 'SERVER_PORT',
|
|
82
|
-
message: 'Server port:',
|
|
83
|
-
default: options.port
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
type: 'input',
|
|
87
|
-
name: 'JWT_SECRET',
|
|
88
|
-
message: 'JWT secret (leave empty to generate):',
|
|
89
|
-
default: ''
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
type: 'input',
|
|
93
|
-
name: 'ADMIN_USER',
|
|
94
|
-
message: 'Admin username:',
|
|
95
|
-
default: 'admin'
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
type: 'password',
|
|
99
|
-
name: 'ADMIN_PASSWD',
|
|
100
|
-
message: 'Admin password:',
|
|
101
|
-
default: 'admin',
|
|
102
|
-
mask: '*'
|
|
103
|
-
}
|
|
104
|
-
]);
|
|
105
|
-
|
|
106
|
-
// 如果没有提供JWT密钥则生成一个
|
|
107
|
-
if (!config.JWT_SECRET) {
|
|
108
|
-
config.JWT_SECRET = require('crypto').randomBytes(32).toString('hex');
|
|
109
|
-
console.log(chalk.green('🔐 Generated JWT secret'));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// 创建.env文件
|
|
113
|
-
const envContent = `# ReactPress Server Configuration
|
|
114
|
-
# Generated on ${new Date().toISOString()}
|
|
45
|
+
// 使用基础配置模板,基于根目录的.env文件
|
|
46
|
+
console.log(chalk.cyan('📋 Creating configuration file based on default template...\n'));
|
|
47
|
+
|
|
48
|
+
// 生成JWT密钥
|
|
49
|
+
const jwtSecret = require('crypto').randomBytes(32).toString('hex');
|
|
50
|
+
console.log(chalk.green('🔐 Generated JWT secret'));
|
|
51
|
+
|
|
52
|
+
// 创建.env文件 - 基于根目录模板
|
|
53
|
+
const envContent = `# Database Config
|
|
54
|
+
DB_HOST=127.0.0.1
|
|
55
|
+
DB_PORT=3306
|
|
56
|
+
DB_USER=reactpress
|
|
57
|
+
DB_PASSWD=reactpress
|
|
58
|
+
DB_DATABASE=reactpress
|
|
59
|
+
|
|
60
|
+
# JWT Secret
|
|
61
|
+
JWT_SECRET=${jwtSecret}
|
|
115
62
|
|
|
116
|
-
#
|
|
117
|
-
|
|
118
|
-
DB_HOST=${config.DB_HOST}
|
|
119
|
-
DB_PORT=${config.DB_PORT}
|
|
120
|
-
DB_USERNAME=${config.DB_USERNAME}
|
|
121
|
-
DB_PASSWORD=${config.DB_PASSWORD}
|
|
122
|
-
DB_DATABASE=${config.DB_DATABASE}
|
|
63
|
+
# Client Config
|
|
64
|
+
CLIENT_SITE_URL=http://localhost:3001
|
|
123
65
|
|
|
124
|
-
# Server
|
|
125
|
-
|
|
66
|
+
# Server Config
|
|
67
|
+
SERVER_SITE_URL=http://localhost:${options.port}
|
|
68
|
+
SERVER_PORT=${options.port}
|
|
126
69
|
SERVER_API_PREFIX=/api
|
|
127
70
|
|
|
128
|
-
#
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
ADMIN_PASSWD=${config.ADMIN_PASSWD}
|
|
71
|
+
# Admin Config
|
|
72
|
+
ADMIN_USER=admin
|
|
73
|
+
ADMIN_PASSWD=admin
|
|
132
74
|
|
|
133
75
|
# Environment
|
|
134
76
|
NODE_ENV=development
|
|
@@ -138,17 +80,19 @@ NODE_ENV=development
|
|
|
138
80
|
console.log(chalk.green('✅ Configuration saved to .env file'));
|
|
139
81
|
|
|
140
82
|
if (!options.skipDbSetup) {
|
|
141
|
-
console.log(chalk.yellow('\n🗄️
|
|
83
|
+
console.log(chalk.yellow('\n🗄️ Database setup:'));
|
|
142
84
|
console.log(chalk.gray(`Please ensure your ${options.database} server is running and create the database:`));
|
|
143
|
-
console.log(chalk.cyan(`CREATE DATABASE
|
|
144
|
-
console.log(chalk.gray('
|
|
85
|
+
console.log(chalk.cyan(`CREATE DATABASE reactpress;`));
|
|
86
|
+
console.log(chalk.gray(`CREATE USER 'reactpress'@'localhost' IDENTIFIED BY 'reactpress';`));
|
|
87
|
+
console.log(chalk.gray(`GRANT ALL PRIVILEGES ON reactpress.* TO 'reactpress'@'localhost';`));
|
|
88
|
+
console.log(chalk.gray(`FLUSH PRIVILEGES;`));
|
|
145
89
|
}
|
|
146
90
|
|
|
147
91
|
console.log(chalk.green('\n🎉 ReactPress Server initialized successfully!'));
|
|
148
92
|
console.log(chalk.cyan('\nNext steps:'));
|
|
149
93
|
console.log(chalk.gray('1. Start the server: npx @fecommunity/reactpress-server start'));
|
|
150
|
-
console.log(chalk.gray('2. Visit API: http://localhost:' +
|
|
151
|
-
console.log(chalk.gray('3. API docs: http://localhost:' +
|
|
94
|
+
console.log(chalk.gray('2. Visit API: http://localhost:' + options.port + '/api'));
|
|
95
|
+
console.log(chalk.gray('3. API docs: http://localhost:' + options.port + '/api (Swagger UI)'));
|
|
152
96
|
});
|
|
153
97
|
|
|
154
98
|
// Start command - 启动服务器
|
|
@@ -224,8 +168,8 @@ program
|
|
|
224
168
|
env
|
|
225
169
|
});
|
|
226
170
|
} else {
|
|
227
|
-
console.log(chalk.yellow('⚠️ Development mode
|
|
228
|
-
console.log(chalk.cyan('Starting
|
|
171
|
+
console.log(chalk.yellow('⚠️ Development mode using built server (source code not available)'));
|
|
172
|
+
console.log(chalk.cyan('Starting server with NODE_ENV=development...'));
|
|
229
173
|
execSync(`node ${serverMainPath}`, {
|
|
230
174
|
cwd: process.cwd(),
|
|
231
175
|
stdio: 'inherit',
|