我有以下代码,可以使用node&restify成功设置http和https端点。
import * as fs from 'fs';
import * as restify from 'restify';
import { settings } from './config/config';
import { Logger } from './services/Logger';
import corsMiddleware = require('restify-cors-middleware');
var compression = require('compression');
var helmet = require('helmet');
var httpOptions = { name: settings.name, key: fs.readFileSync('./Certificate/key.pem'), certificate: fs.readFileSync('./Certificate/cert.pem') }
export let httpServer = restify.createServer({ name: settings.name });
export let httpsServer = restify.createServer(httpOptions);
// Bunch of configuration done here removed ...
httpServer.listen(settings.httpPort, function () {
Logger.info(`INFO: ${httpServer.name} is running at ${httpServer.url}`);
});
httpsServer.listen(settings.httpsPort, function () {
Logger.info(`INFO: ${httpsServer.name} is running at ${httpsServer.url}`);
});
启动时,我得到以下输出:
信息:跟踪器服务正在http://[::]:8082上运行
信息:跟踪器服务正在https://[::]:8443上运行
我可以通过http和https成功连接。现在,我想将其移至使用pfx,因此尝试了这段代码
import * as fs from 'fs';
import * as restify from 'restify';
import { settings } from './config/config';
import { Logger } from './services/Logger';
import corsMiddleware = require('restify-cors-middleware');
var compression = require('compression');
var helmet = require('helmet');
var httpOptions = { name: settings.name, httpsServerOptions: { pfx: fs.readFileSync('./Certificate/systema.pfx'), passphrase: 'passphrase' } }
// Also tried this to no avail
//var httpOptions = { name: settings.name, pfx: fs.readFileSync('./Certificate/systema.pfx'), passphrase: 'passphrase' }
export let httpServer = restify.createServer({ name: settings.name });
export let httpsServer = restify.createServer(httpOptions);
// Bunch of configuration done here removed ...
httpServer.listen(settings.httpPort, function () {
Logger.info(`INFO: ${httpServer.name} is running at ${httpServer.url}`);
});
httpsServer.listen(settings.httpsPort, function () {
Logger.info(`INFO: ${httpsServer.name} is running at ${httpsServer.url}`);
});
但这会生成输出
信息:跟踪器服务正在http://[::]:8082上运行
信息:跟踪器服务正在http://[::]:8443上运行
请注意第二行上的http://。
关于如何使pfx选项起作用的任何想法吗?