Skip to content

Commit 288b501

Browse files
committed
feat(server): https 证书/秘钥改为全局配置
1 parent 5e46a70 commit 288b501

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/commands/server.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,18 @@ exports.run = function (options) {
389389

390390
servers.push(extend(http.createServer(app), { _port: port }));
391391
if (isHttps) {
392+
var globalConfig = JSON.parse(fs.readFileSync(YKIT_RC, { encoding: 'utf8' }));
393+
394+
if (!globalConfig['https-key'] || !globalConfig['https-crt']) {
395+
warn('缺少 https 证书/秘钥配置,请使用以下命令设置:');
396+
!globalConfig['https-key'] && warn('ykit config set https-key <path-to-your-key>');
397+
!globalConfig['https-crt'] && warn('ykit config set https-crt <path-to-your-crt>');
398+
process.exit(1);
399+
}
400+
392401
var httpsOpts = {
393-
key: fs.readFileSync(sysPath.join(__dirname, '../config/https/server.key')),
394-
cert: fs.readFileSync(sysPath.join(__dirname, '../config/https/server.crt'))
402+
key: fs.readFileSync(globalConfig['https-key']),
403+
cert: fs.readFileSync(globalConfig['https-crt'])
395404
};
396405
servers.push(extend(https.createServer(httpsOpts, app), { _port: '443', _isHttps: true }));
397406
}

src/commands/server.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,18 @@ exports.run = (options) => {
371371

372372
servers.push(extend(http.createServer(app), {_port: port}));
373373
if (isHttps) {
374+
const globalConfig = JSON.parse(fs.readFileSync(YKIT_RC, {encoding: 'utf8'}));
375+
376+
if(!globalConfig['https-key'] || !globalConfig['https-crt']) {
377+
warn('缺少 https 证书/秘钥配置,请使用以下命令设置:');
378+
!globalConfig['https-key'] && warn('ykit config set https-key <path-to-your-key>');
379+
!globalConfig['https-crt'] && warn('ykit config set https-crt <path-to-your-crt>');
380+
process.exit(1);
381+
}
382+
374383
const httpsOpts = {
375-
key: fs.readFileSync(sysPath.join(__dirname, '../config/https/server.key')),
376-
cert: fs.readFileSync(sysPath.join(__dirname, '../config/https/server.crt'))
384+
key: fs.readFileSync(globalConfig['https-key']),
385+
cert: fs.readFileSync(globalConfig['https-crt'])
377386
};
378387
servers.push(extend(https.createServer(httpsOpts, app), {_port: '443', _isHttps: true}));
379388
}

0 commit comments

Comments
 (0)