vk-ssl-auto-deploy 0.0.3 → 0.1.1

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/README.md CHANGED
@@ -1,79 +1,130 @@
1
- ### 1. NPM 全局安装(推荐)
2
-
3
- 安装node环境
1
+ ## 安装部署
2
+
3
+ ### 1. 安装node环境(如果node环境已安装,则跳过这一步骤)
4
+
5
+ #### linux系统
4
6
 
5
7
  ```bash
6
- curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
7
- sudo yum install -y nodejs
8
- ```
8
+ curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash - && sudo yum install -y nodejs
9
+ ```
10
+
11
+ #### Windows系统
12
+
13
+ ```bash
14
+ winget install --id OpenJS.NodeJS.LTS -e
15
+ ```
9
16
 
10
- 验证npm
17
+ 验证是否完成完成
11
18
 
12
19
  ```bash
13
- node -v
14
- npm -v
20
+ node -v && npm -v
15
21
  ```
16
22
 
17
- 安装pm2
23
+ ### 2. 安装pm2
18
24
 
19
25
  ```bash
20
26
  npm install -g pm2
21
27
  ```
22
28
 
23
- 安装自动部署工具
29
+ ### 3. 安装证书自动部署工具
24
30
 
25
31
  ```bash
26
32
  npm install -g vk-ssl-auto-deploy@latest
27
33
  ```
28
34
 
29
- 查看安装目录
35
+ ### 4. 查看安装目录
30
36
 
31
37
  ```bash
32
38
  npm root -g
33
- ```
34
-
35
- 在返回的结果中拼接 `/vk-ssl-auto-deploy`
36
-
37
- `/usr/lib/node_modules/vk-ssl-auto-deploy`
38
-
39
- ### 2. 启动
39
+ ```
40
+
41
+ 假设返回 `/usr/lib/node_modules`
42
+
43
+ 则执行命令 `cd /usr/lib/node_modules/vk-ssl-auto-deploy` 进入工具目录
44
+
45
+ ### 5. 修改部署成功回调命令
46
+
47
+ 查看配置文件 [查看配置说明](#配置说明)
48
+
49
+ ```bash
50
+ vim config.json
51
+ ```
52
+
53
+ 编辑配置文件
54
+
55
+ **基本操作:**
56
+
57
+ - 按 i - 进入插入模式(可以编辑)
58
+ - 按 ESC - 退出插入模式
59
+ - 输入 :wq - 保存并退出
60
+ - 输入 :q! - 不保存退出
61
+ - 输入 :w - 仅保存
62
+
63
+ Linux系统下重载nginx配置
64
+
65
+ ```bash
66
+ sudo nginx -t && sudo service nginx reload
67
+ ```
68
+
69
+ Windows系统下重载nginx配置(注意:地址需要用 / 不能用 \)
70
+
71
+ ```bash
72
+ cd C:/Users/Administrator/Desktop/nginx-openresty-1.15.8.1-win64&nginx.exe -s reload
73
+ ```
74
+
75
+ ### 6. 启动程序
40
76
 
41
77
  安装后可以直接使用命令启动:
42
78
 
43
79
  ```bash
44
- # 直接启动
80
+ # 调试启动(关闭命令窗口后程序会停止运行)
45
81
  vk-ssl
46
-
47
- # 或使用 PM2 管理(需要先安装 PM2)
48
- npm install -g pm2
82
+
83
+ # mp2方式运行(关闭命令窗口后程序依然会运行)
49
84
  cd <安装目录>,如 cd /usr/lib/node_modules/vk-ssl-auto-deploy
50
85
  npm run start
86
+ ```
87
+
88
+ **注意服务器需要开放端口:6001**
89
+
90
+ ## 配置说明
91
+
92
+ 编辑 `config.json` 文件可以修改服务端口和路由前缀:
93
+
94
+ ```json
95
+ {
96
+ "port": 6001,
97
+ "routerName": "api",
98
+ "certPath": "/vk-cert",
99
+ "ipWhitelist": [],
100
+ "callbackCommand": [
101
+ "sudo nginx -t && sudo service nginx reload"
102
+ ]
103
+ }
51
104
  ```
52
105
 
106
+ - `port`: 服务监听端口(默认 6001)(一般无需改动)
107
+ - `routerName`: API 路由前缀(默认 "api",即访问路径为 `/api/...`)(一般无需改动)
108
+ - `certPath`: 证书存储目录,最终证书路径为 `${certPath}/${证书id}/`(一般无需改动)
109
+ - `ipWhitelist`: IP白名单,默认为空,表示不限制IP,如果需要限制IP,可以填写IP地址,多个IP地址用逗号分隔
110
+ - `callbackCommand`: 证书部署成功后执行的服务器命令,一般用于重载nginx配置等
111
+
112
+ ## 进入证书目录
113
+
53
114
  ```js
54
- cd /usr/lib/node_modules/vk-ssl-auto-deploy/cert
55
- ```
115
+ cd /vk-cert ; ls
116
+ ```
56
117
 
57
- ### 3. 本地开发安装
118
+ ## PM2 进程管理
58
119
 
59
120
  ```bash
60
- # 克隆项目
61
- git clone <repository-url>
62
- cd vk-ssl-auto-deploy
63
-
64
- # 安装依赖
65
- npm install
66
-
67
- # 启动运行
68
- npm dev
69
- ```
70
-
71
- ### 4. PM2 进程管理(生产环境推荐)
121
+ cd /usr/lib/node_modules/vk-ssl-auto-deploy
72
122
 
73
- ```bash
74
123
  # 启动服务
75
124
  npm run start
76
125
 
126
+ 或直接 npm --prefix /usr/lib/node_modules/vk-ssl-auto-deploy run start
127
+
77
128
  # 停止服务
78
129
  npm run stop
79
130
 
@@ -90,25 +141,25 @@ npm run delete
90
141
  npm run list
91
142
  ```
92
143
 
93
- ### 5. 证书自动部署API
144
+ ## 证书自动部署API
94
145
 
95
- #### 接口说明
146
+ ### 接口说明
96
147
 
97
148
  证书续期后台可以通过HTTP POST请求将证书文件自动部署到本项目。
98
149
 
99
- #### 请求地址
150
+ ### 请求地址
100
151
 
101
152
  ```
102
153
  POST http://your-domain:3000/api/deploy-cert
103
154
  ```
104
155
 
105
- #### 请求参数
156
+ ### 请求参数
106
157
 
107
158
  - Content-Type: `multipart/form-data`
108
159
  - `name`: 证书名称(必填),用于创建子目录,例如 `aaa` 会创建 `cert/aaa` 目录
109
160
  - `file`: zip格式的证书文件(必填)
110
161
 
111
- #### 返回格式
162
+ ### 返回格式
112
163
 
113
164
  成功响应:
114
165
  ```json
@@ -128,7 +179,7 @@ POST http://your-domain:3000/api/deploy-cert
128
179
  }
129
180
  ```
130
181
 
131
- #### 错误码说明
182
+ ### 错误码说明
132
183
 
133
184
  - `1001`: 缺少参数 name
134
185
  - `1002`: 缺少文件
@@ -136,7 +187,7 @@ POST http://your-domain:3000/api/deploy-cert
136
187
  - `2001`: 解压zip文件失败
137
188
  - `5000`: 服务器内部错误
138
189
 
139
- #### 证书文件说明
190
+ ### 证书文件说明
140
191
 
141
192
  上传的zip文件解压后应包含以下内容:
142
193
 
@@ -152,7 +203,7 @@ POST http://your-domain:3000/api/deploy-cert
152
203
  - cert.pfx(pfx格式证书文件,iis服务器使用)
153
204
  - one.pem(证书和私钥简单合并成一个文件,pem格式,crt正文+key正文)
154
205
 
155
- #### 使用示例
206
+ ### 使用示例
156
207
 
157
208
  使用curl命令:
158
209
  ```bash
@@ -175,64 +226,6 @@ fetch('http://localhost:3000/api/deploy-cert', {
175
226
  .then(data => console.log(data));
176
227
  ```
177
228
 
178
- ### 6. 配置说明
179
-
180
- 编辑 `config.json` 文件可以修改服务端口和路由前缀:
181
-
182
- ```json
183
- {
184
- "port": 6001,
185
- "routerName": "api",
186
- "ipWhitelist": []
187
- }
188
- ```
189
-
190
- - `port`: 服务监听端口(默认 6001)
191
- - `routerName`: API 路由前缀(默认 "api",即访问路径为 `/api/...`)
192
- - `ipWhitelist`: IP白名单,默认为空,表示不限制IP,如果需要限制IP,可以填写IP地址,多个IP地址用逗号分隔
193
-
194
- ### 7. License
195
-
196
- MIT
197
-
198
- ### 8. 发布到 NPM(维护者使用)
199
-
200
- #### 发布前准备
201
-
202
- 1. 确保已登录 npm 账号:
203
- ```bash
204
- npm login
205
- ```
206
-
207
- 2. 更新版本号(遵循语义化版本):
208
- ```bash
209
- # 修复bug
210
- npm version patch
211
-
212
- # 新功能
213
- npm version minor
214
-
215
- # 破坏性更新
216
- npm version major
217
- ```
218
-
219
- #### 发布命令
220
-
221
- ```bash
222
- # 发布到 npm
223
- npm publish
224
-
225
- # 如果是第一次发布公开包
226
- npm publish --access public
227
- ```
228
-
229
- #### 测试包
230
-
231
- 发布前可以本地测试:
232
- ```bash
233
- # 打包测试
234
- npm pack
229
+ ## License
235
230
 
236
- # 本地安装测试
237
- npm install -g ./vk-ssl-auto-deploy-1.0.0.tgz
238
- ```
231
+ MIT
package/config.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "port": 6001,
3
3
  "routerName": "api",
4
4
  "ipWhitelist": [],
5
+ "certPath": "/vk-cert",
5
6
  "callbackCommand": [
6
7
  "sudo nginx -t && sudo service nginx reload"
7
8
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vk-ssl-auto-deploy",
3
- "version": "0.0.3",
3
+ "version": "0.1.1",
4
4
  "description": "SSL证书自动部署工具 - 提供HTTP API接口,支持证书文件自动上传和部署",
5
5
  "main": "app.js",
6
6
  "bin": {
@@ -1,8 +1,8 @@
1
- body {
2
- padding: 50px;
3
- font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4
- }
5
-
6
- a {
7
- color: #00B7FF;
8
- }
1
+ body {
2
+ padding: 50px;
3
+ font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4
+ }
5
+
6
+ a {
7
+ color: #00B7FF;
8
+ }
package/routes/cert.js CHANGED
@@ -65,8 +65,11 @@ router.post('/deploy-cert', upload.single('file'), async (req, res, next) => {
65
65
 
66
66
  // 2. 创建cert目录和子目录
67
67
  const projectRoot = path.join(__dirname, '..');
68
- const certBaseDir = path.join(projectRoot, 'cert');
69
- const certDir = path.join(certBaseDir, certName);
68
+ // 使用配置文件中的 certPath,支持绝对路径和相对路径
69
+ const certBaseDir = path.isAbsolute(config.certPath)
70
+ ? config.certPath
71
+ : path.join(projectRoot, config.certPath);
72
+ const certDir = path.resolve(certBaseDir, certName);
70
73
 
71
74
  // 确保cert根目录存在
72
75
  if (!fs.existsSync(certBaseDir)) {
@@ -159,7 +162,7 @@ router.post('/deploy-cert', upload.single('file'), async (req, res, next) => {
159
162
  });
160
163
  }
161
164
 
162
- console.log(`[证书部署成功] 名称: ${certName}, 路径: ${certDir}, 保存: ${stats.saved}个, 过滤: ${stats.filtered}个`);
165
+ console.log(`[证书部署成功] 名称: ${certName}, 路径: ${certDir.replace(/\\/g, '/')}, 保存: ${stats.saved}个, 过滤: ${stats.filtered}个`);
163
166
 
164
167
  // 4. 执行回调命令
165
168
  const commandResults = [];
@@ -211,7 +214,7 @@ router.post('/deploy-cert', upload.single('file'), async (req, res, next) => {
211
214
  return res.json({
212
215
  code: 0,
213
216
  msg: '证书部署成功',
214
- path: 'cert/' + certName,
217
+ path: path.join(config.certPath, certName),
215
218
  stats: {
216
219
  total: stats.total,
217
220
  saved: stats.saved,
package/views/error.ejs CHANGED
@@ -1,3 +1,3 @@
1
- <h1><%= message %></h1>
2
- <h2><%= error.status %></h2>
3
- <pre><%= error.stack %></pre>
1
+ <h1><%= message %></h1>
2
+ <h2><%= error.status %></h2>
3
+ <pre><%= error.stack %></pre>
package/views/index.ejs CHANGED
@@ -1,10 +1,10 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title><%= title %></title>
5
- <link rel='stylesheet' href='/stylesheets/style.css' />
6
- </head>
7
- <body>
8
- <h1><%= title %></h1>
9
- </body>
10
- </html>
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= title %></title>
5
+ <link rel='stylesheet' href='/stylesheets/style.css' />
6
+ </head>
7
+ <body>
8
+ <h1><%= title %></h1>
9
+ </body>
10
+ </html>