-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: read https config from app:config #75
base: master
Are you sure you want to change the base?
Conversation
问题在这儿 https://cnodejs.org/topic/5b7ac9c7c52ad1482eb940bf#5b8675012a585e4e2f26ffc0 address.protocal = this.options.https ? 'https' : 'http';
address.port = this.options.sticky ? this[REALPORT] : address.port;
this[APP_ADDRESS] = getAddress(address); 这儿用的是 |
Codecov Report
@@ Coverage Diff @@
## master #75 +/- ##
=========================================
+ Coverage 98.35% 98.66% +0.3%
=========================================
Files 7 8 +1
Lines 425 448 +23
=========================================
+ Hits 418 442 +24
+ Misses 7 6 -1
Continue to review full report at Codecov.
|
你的 master 太旧了,要 rebase |
新pull了才开的分支啊。。。 |
看下 GitHub 帮助里面,如何 sync upstream,或者删掉重新 fork (原代码要注意) |
看了下,和 upstream 就差一个提交 b0c8d19 。 倒是 upstream 的版本tag没有同步下来 |
master.js 如何获取到 app.config.cluster 配置值 这个不知道如何处理 |
@atian25 咨询个 egg 在 vsc debug的配置问题
修改 vsc 配置
得空还是考虑用TS重写下egg吧,调试起来效率真不高,一个参数不知道在哪儿会被修改…… |
lib/app_worker.js
Outdated
if (https) { | ||
const httpsOptions = Object.assign({}, https, { | ||
key: fs.readFileSync(https.key), | ||
cert: fs.readFileSync(https.cert), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 需要补测试
- 既然是
listenConfig.https
的话,可以考虑支持全部的 options,而不只是这 2 个,https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options - options.https 的优先级更高 (要测试覆盖)
const httpsOptions = Object.assign({}, listenConfig.https, options.https);
httpsOptions.key = fs.readFileSync(httpsOptions.key);
httpsOptions.cert = fs.readFileSync(httpsOptions.cert);
httpsOptions.pfx = fs.readFileSync(httpsOptions.pfx);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/eggjs/egg-cluster/pull/75/files/c7af27258d297eb0a08094b64b3055496b02f63d#diff-ee1e398c8b3f724318c68cc38d3bde50R24
const https = options.https || listenConfig.https;
这儿是优先使用 options.https 参数的。
这个测试的判断不知道咋写。另外如果用这个PR启动了https,但是控制台输出日志里面还是 http 而不是 https。如果日志不修改,测试也不好做判断吧。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const https = options.https || listenConfig.https;
这样是 2 选 1,assign 的话,就可以外部传递来覆盖。
不过都行,一般也不需要覆盖。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要支持下其他的配置,印象中 passphrase 之前有人提过。
pfx 这个也可以顺便支持下 readFileSync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试是可以通过 Controller 去输出 protocol 的吧,@popomore test/fixtures/server.key 这个好像开源后就没对应的测试了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你的意思是 https 里面的值要支持单独覆盖? 我之前考虑过是整体覆盖还是细节覆盖,先实现的是整体。
其他配置参数的测试用例估计比较麻烦吧……
readFile 你指的是异步读取证书?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readFile 你指的是异步读取证书
不是,pfx 是 key 和 cert 的替代品,一般也是文件内容,所以顺便也 readFileSync 下。
你的意思是 https 里面的值要支持单独覆盖? 我之前考虑过是整体覆盖还是细节覆盖,先实现的是整体。
都行,我之前的想法是 assign
其他配置参数的测试用例估计比较麻烦吧……
不需要,我们只需要测试能启动 https 就 ok 了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atian25 处理完 listenConfig.https 的参数后是否更新到 options.https 上以便后续使用?
master 不需要获取
非相关问题可以其他渠道沟通
TS 解决不了问题,也没计划考虑重写。 |
This comment has been minimized.
This comment has been minimized.
protocol 那个,@popomore 有什么建议? |
describe('options with https', () => {
let app;
before(() => {
app = utils.cluster('apps/options', {
framework: path.dirname(require.resolve('egg')),
https: {
key: '/key.unsecure',
cert: '/02.crt',
},
port: 7701,
});
return app.ready();
});
after(() => app.close());
it('should be passed through', () => {
return app.httpRequest()
.get('/')
.expect('true');
});
}); egg-mock 异常
|
重构处理证书逻辑: 先合并参数,最后启动app_worker 时再验证、加载证书。适用于当配置的证书(文件)无效(不存在、过期等)时可在不修改代码情况下临时通过命令行指定有效的证书文件路径启动服务的情况。 |
@tofix log print http not https cause master.js@Line469 use this.options.https
validate cert file exists during start worker
test exists in tls_options.test.js
没人看看? |
@dead-horse @popomore 瞅瞅? |
所以这里是有解决从config读https配置了吗?还是说还是只能 |
这个问题应该没解决: |
那这里是解决了什么问题? |
从 package.json 读取证书配置没问题,就是日志显示 protocol 不正常 |
谢谢!之后会支持通过配置去开启https吗?而不是通过package.json |
按道理在命令行启动时额外传入证书参数也是可行的。这个我没测试。 |
可以支持类似配置吗? |
@catherinessssss |
// lib/test.js
protocol = app instanceof https.Server ? 'https' : 'http';
// lib/cluster.js
let clusterApp = new ClusterApplication(options);
clusterApp = new Proxy(clusterApp, {
//...
});
return clusterApp;
|
这样实现貌似也可以? // lib/app_worker.js
// ...L25
const httpsOptions = Object.assign({}, clusterConfig.https, options.https);
const protocal = (httpsOptions.key && httpsOptions.cert) ? 'https' : 'http';
process.send({
to: 'master',
action: 'realprotocal',
data: protocal,
}); // lib/master.js
const REALPROTOCAL = Symbol('Master#realprotocal');
class Master extends EventEmitter {
constructor(options) {
this[REALPORT] = undefined;
// ...
this.on('realprotocal', protocal => {
if (protocal) this[REALPROTOCAL] = protocal;
});
}
}
// L586
address.protocal = this[REALPROTOCAL] || (this.options.https ? 'https' : 'http'); |
@tofix log print http not https cause master.js@Line469 use this.options.https
Checklist
npm test
passesAffected core subsystem(s)
Description of change