vk-ssl-auto-deploy 0.0.2 → 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
- npm install -g vk-ssl-auto-deploy
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
 
@@ -50,7 +72,13 @@ cd <安装目录>,如 cd /usr/lib/node_modules/vk-ssl-auto-deploy
50
72
  npm run start
51
73
  ```
52
74
 
53
- ### 3. 本地开发安装
75
+ ```js
76
+ cd /usr/lib/node_modules/vk-ssl-auto-deploy/cert
77
+ ```
78
+
79
+ 注意服务器需要开放端口:6001
80
+
81
+ ## 3. 本地开发安装
54
82
 
55
83
  ```bash
56
84
  # 克隆项目
@@ -61,15 +89,19 @@ cd vk-ssl-auto-deploy
61
89
  npm install
62
90
 
63
91
  # 启动运行
64
- npm dev
92
+ npm run dev
65
93
  ```
66
94
 
67
- ### 4. PM2 进程管理(生产环境推荐)
95
+ ## 4. PM2 进程管理(生产环境推荐)
68
96
 
69
97
  ```bash
98
+ cd /usr/lib/node_modules/vk-ssl-auto-deploy
99
+
70
100
  # 启动服务
71
101
  npm run start
72
102
 
103
+ 或直接 npm --prefix /usr/lib/node_modules/vk-ssl-auto-deploy run start
104
+
73
105
  # 停止服务
74
106
  npm run stop
75
107
 
@@ -86,25 +118,25 @@ npm run delete
86
118
  npm run list
87
119
  ```
88
120
 
89
- ### 5. 证书自动部署API
121
+ ## 5. 证书自动部署API
90
122
 
91
- #### 接口说明
123
+ ### 接口说明
92
124
 
93
125
  证书续期后台可以通过HTTP POST请求将证书文件自动部署到本项目。
94
126
 
95
- #### 请求地址
127
+ ### 请求地址
96
128
 
97
129
  ```
98
130
  POST http://your-domain:3000/api/deploy-cert
99
131
  ```
100
132
 
101
- #### 请求参数
133
+ ### 请求参数
102
134
 
103
135
  - Content-Type: `multipart/form-data`
104
136
  - `name`: 证书名称(必填),用于创建子目录,例如 `aaa` 会创建 `cert/aaa` 目录
105
137
  - `file`: zip格式的证书文件(必填)
106
138
 
107
- #### 返回格式
139
+ ### 返回格式
108
140
 
109
141
  成功响应:
110
142
  ```json
@@ -124,7 +156,7 @@ POST http://your-domain:3000/api/deploy-cert
124
156
  }
125
157
  ```
126
158
 
127
- #### 错误码说明
159
+ ### 错误码说明
128
160
 
129
161
  - `1001`: 缺少参数 name
130
162
  - `1002`: 缺少文件
@@ -132,7 +164,7 @@ POST http://your-domain:3000/api/deploy-cert
132
164
  - `2001`: 解压zip文件失败
133
165
  - `5000`: 服务器内部错误
134
166
 
135
- #### 证书文件说明
167
+ ### 证书文件说明
136
168
 
137
169
  上传的zip文件解压后应包含以下内容:
138
170
 
@@ -148,7 +180,7 @@ POST http://your-domain:3000/api/deploy-cert
148
180
  - cert.pfx(pfx格式证书文件,iis服务器使用)
149
181
  - one.pem(证书和私钥简单合并成一个文件,pem格式,crt正文+key正文)
150
182
 
151
- #### 使用示例
183
+ ### 使用示例
152
184
 
153
185
  使用curl命令:
154
186
  ```bash
@@ -171,7 +203,7 @@ fetch('http://localhost:3000/api/deploy-cert', {
171
203
  .then(data => console.log(data));
172
204
  ```
173
205
 
174
- ### 6. 配置说明
206
+ ## 6. 配置说明
175
207
 
176
208
  编辑 `config.json` 文件可以修改服务端口和路由前缀:
177
209
 
@@ -179,56 +211,16 @@ fetch('http://localhost:3000/api/deploy-cert', {
179
211
  {
180
212
  "port": 6001,
181
213
  "routerName": "api",
214
+ "certPath": "../../../vk-cert",
182
215
  "ipWhitelist": []
183
216
  }
184
217
  ```
185
218
 
186
219
  - `port`: 服务监听端口(默认 6001)
187
- - `routerName`: API 路由前缀(默认 "api",即访问路径为 `/api/...`)
220
+ - `routerName`: API 路由前缀(默认 "api",即访问路径为 `/api/...`)
221
+ - `certPath`: 证书存储目录,最终证书路径为 `${certPath}/${证书id}/`
188
222
  - `ipWhitelist`: IP白名单,默认为空,表示不限制IP,如果需要限制IP,可以填写IP地址,多个IP地址用逗号分隔
189
223
 
190
- ### 7. License
191
-
192
- MIT
193
-
194
- ### 8. 发布到 NPM(维护者使用)
195
-
196
- #### 发布前准备
197
-
198
- 1. 确保已登录 npm 账号:
199
- ```bash
200
- npm login
201
- ```
202
-
203
- 2. 更新版本号(遵循语义化版本):
204
- ```bash
205
- # 修复bug
206
- npm version patch
207
-
208
- # 新功能
209
- npm version minor
210
-
211
- # 破坏性更新
212
- npm version major
213
- ```
214
-
215
- #### 发布命令
216
-
217
- ```bash
218
- # 发布到 npm
219
- npm publish
220
-
221
- # 如果是第一次发布公开包
222
- npm publish --access public
223
- ```
224
-
225
- #### 测试包
226
-
227
- 发布前可以本地测试:
228
- ```bash
229
- # 打包测试
230
- npm pack
224
+ ## 7. License
231
225
 
232
- # 本地安装测试
233
- npm install -g ./vk-ssl-auto-deploy-1.0.0.tgz
234
- ```
226
+ MIT
package/config.json CHANGED
@@ -2,7 +2,8 @@
2
2
  "port": 6001,
3
3
  "routerName": "api",
4
4
  "ipWhitelist": [],
5
+ "certPath": "/vk-cert",
5
6
  "callbackCommand": [
6
- "sudo nginx -t && sudo systemctl reload nginx"
7
+ "sudo nginx -t && sudo service nginx reload"
7
8
  ]
8
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vk-ssl-auto-deploy",
3
- "version": "0.0.2",
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>