Skip to content
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

SSL 证书重载 #630

Merged
merged 3 commits into from
Feb 16, 2023
Merged

SSL 证书重载 #630

merged 3 commits into from
Feb 16, 2023

Conversation

bruce48x
Copy link
Contributor

HybriConnector 加载 ssl 证书后不会自动刷新,现在加上文件监听,就可以不重启服务器来刷新 SSL 证书。
给 connectorConfig 增加 sslWatcher 即可
代码:
app.ts

const sslKeyPath = './config/server.key';
const sslCertPath = './config/server.crt';

function readCertsSync() {
    return {
        key: fs.readFileSync(sslKeyPath),
        cert: fs.readFileSync(sslCertPath)
    }
}

// app configuration
app.configure('production|development', 'connector', function () {
    const sslOpt:tls.SecureContextOptions = readCertsSync();
    app.set('connectorConfig',
        {
            connector: pinus.connectors.hybridconnector,
            heartbeat: 3,
            useDict: true,
            useProtobuf: true,
            ssl: sslOpt,
            sslWatcher: (cb) => {
                fs.watch(sslKeyPath, () => {
                    cb(readCertsSync());
                });
            }
        });
});

@whtiehack whtiehack merged commit 9f5bf8c into node-pinus:master Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants