当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Node.js https.createServer([options][, requestListener])用法及代码示例

https.createServer([options][, requestListener])

添加于:v0.3.4

参数
// curl -k https://localhost:8000/
const https = require('node:https');
const fs = require('node:fs');

const options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};

https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(8000);

或者

const https = require('node:https');
const fs = require('node:fs');

const options = {
  pfx: fs.readFileSync('test/fixtures/test_cert.pfx'),
  passphrase: 'sample'
};

https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(8000);

相关用法


注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 https.createServer([options][, requestListener])。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。