vk-ssl-auto-deploy 0.0.3 → 0.1.0

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,42 +1,64 @@
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
- ```
39
+ ```
40
+
41
+ 修改部署成功回调命令
42
+
43
+ Linux系统下重载nginx配置
44
+
45
+ ```bash
46
+ sudo nginx -t && sudo service nginx reload
47
+ ```
48
+
49
+ Windows系统下重载nginx配置
50
+ ```bash
51
+ // 注意:地址需要用 / 不能用 \
52
+ cd C:/Users/Administrator/Desktop/nginx-openresty-1.15.8.1-win64&nginx.exe -s reload
53
+ ```
34
54
 
35
55
  在返回的结果中拼接 `/vk-ssl-auto-deploy`
36
56
 
37
- 如 `/usr/lib/node_modules/vk-ssl-auto-deploy`
38
-
39
- ### 2. 启动
57
+ linux系统可能是 `/usr/lib/node_modules/vk-ssl-auto-deploy`
58
+
59
+ Windows系统可能是 `C:\Users\Administrator\AppData\Roaming\npm\node_modules\vk-ssl-auto-deploy`
60
+
61
+ ## 2. 启动
40
62
 
41
63
  安装后可以直接使用命令启动:
42
64
 
@@ -52,9 +74,11 @@ npm run start
52
74
 
53
75
  ```js
54
76
  cd /usr/lib/node_modules/vk-ssl-auto-deploy/cert
55
- ```
77
+ ```
78
+
79
+ 注意服务器需要开放端口:6001
56
80
 
57
- ### 3. 本地开发安装
81
+ ## 3. 本地开发安装
58
82
 
59
83
  ```bash
60
84
  # 克隆项目
@@ -65,15 +89,19 @@ cd vk-ssl-auto-deploy
65
89
  npm install
66
90
 
67
91
  # 启动运行
68
- npm dev
92
+ npm run dev
69
93
  ```
70
94
 
71
- ### 4. PM2 进程管理(生产环境推荐)
95
+ ## 4. PM2 进程管理(生产环境推荐)
72
96
 
73
97
  ```bash
98
+ cd /usr/lib/node_modules/vk-ssl-auto-deploy
99
+
74
100
  # 启动服务
75
101
  npm run start
76
102
 
103
+ 或直接 npm --prefix /usr/lib/node_modules/vk-ssl-auto-deploy run start
104
+
77
105
  # 停止服务
78
106
  npm run stop
79
107
 
@@ -90,25 +118,25 @@ npm run delete
90
118
  npm run list
91
119
  ```
92
120
 
93
- ### 5. 证书自动部署API
121
+ ## 5. 证书自动部署API
94
122
 
95
- #### 接口说明
123
+ ### 接口说明
96
124
 
97
125
  证书续期后台可以通过HTTP POST请求将证书文件自动部署到本项目。
98
126
 
99
- #### 请求地址
127
+ ### 请求地址
100
128
 
101
129
  ```
102
130
  POST http://your-domain:3000/api/deploy-cert
103
131
  ```
104
132
 
105
- #### 请求参数
133
+ ### 请求参数
106
134
 
107
135
  - Content-Type: `multipart/form-data`
108
136
  - `name`: 证书名称(必填),用于创建子目录,例如 `aaa` 会创建 `cert/aaa` 目录
109
137
  - `file`: zip格式的证书文件(必填)
110
138
 
111
- #### 返回格式
139
+ ### 返回格式
112
140
 
113
141
  成功响应:
114
142
  ```json
@@ -128,7 +156,7 @@ POST http://your-domain:3000/api/deploy-cert
128
156
  }
129
157
  ```
130
158
 
131
- #### 错误码说明
159
+ ### 错误码说明
132
160
 
133
161
  - `1001`: 缺少参数 name
134
162
  - `1002`: 缺少文件
@@ -136,7 +164,7 @@ POST http://your-domain:3000/api/deploy-cert
136
164
  - `2001`: 解压zip文件失败
137
165
  - `5000`: 服务器内部错误
138
166
 
139
- #### 证书文件说明
167
+ ### 证书文件说明
140
168
 
141
169
  上传的zip文件解压后应包含以下内容:
142
170
 
@@ -152,7 +180,7 @@ POST http://your-domain:3000/api/deploy-cert
152
180
  - cert.pfx(pfx格式证书文件,iis服务器使用)
153
181
  - one.pem(证书和私钥简单合并成一个文件,pem格式,crt正文+key正文)
154
182
 
155
- #### 使用示例
183
+ ### 使用示例
156
184
 
157
185
  使用curl命令:
158
186
  ```bash
@@ -175,7 +203,7 @@ fetch('http://localhost:3000/api/deploy-cert', {
175
203
  .then(data => console.log(data));
176
204
  ```
177
205
 
178
- ### 6. 配置说明
206
+ ## 6. 配置说明
179
207
 
180
208
  编辑 `config.json` 文件可以修改服务端口和路由前缀:
181
209
 
@@ -183,56 +211,16 @@ fetch('http://localhost:3000/api/deploy-cert', {
183
211
  {
184
212
  "port": 6001,
185
213
  "routerName": "api",
214
+ "certPath": "../../../vk-cert",
186
215
  "ipWhitelist": []
187
216
  }
188
217
  ```
189
218
 
190
219
  - `port`: 服务监听端口(默认 6001)
191
- - `routerName`: API 路由前缀(默认 "api",即访问路径为 `/api/...`)
220
+ - `routerName`: API 路由前缀(默认 "api",即访问路径为 `/api/...`)
221
+ - `certPath`: 证书存储目录,最终证书路径为 `${certPath}/${证书id}/`
192
222
  - `ipWhitelist`: IP白名单,默认为空,表示不限制IP,如果需要限制IP,可以填写IP地址,多个IP地址用逗号分隔
193
223
 
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
224
+ ## 7. License
235
225
 
236
- # 本地安装测试
237
- npm install -g ./vk-ssl-auto-deploy-1.0.0.tgz
238
- ```
226
+ 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.0",
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>