https.createServer([options][, requestListener])
添加于:v0.3.4
参数
options
<Object> 接受来自tls.createServer()
tls.createSecureContext()
http.createServer()
options
。requestListener
<Function> 要添加到'request'
事件的侦听器。- 返回: <https.Server>
// 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);
相关用法
- Node.js https.request(url[, options][, callback])用法及代码示例
- Node.js https.request()用法及代码示例
- Node.js https.get(url[, options][, callback])用法及代码示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代码示例
- Node.js http.Agent.reuseSocket(socket, request)用法及代码示例
- Node.js http2session.destroyed用法及代码示例
- Node.js http.ServerResponse.setTimeout()用法及代码示例
- Node.js http2.connect(authority[, options][, listener])用法及代码示例
- Node.js http2session.type用法及代码示例
- Node.js http.server.keepAliveTimeout用法及代码示例
- Node.js http.validateHeaderValue(name, value)用法及代码示例
- Node.js http2.bufferSize用法及代码示例
- Node.js http.ClientRequest.maxHeadersCount用法及代码示例
- Node.js http.IncomingMessage.httpVersion用法及代码示例
- Node.js http.IncomingMessage.method用法及代码示例
- Node.js http2session.ping()用法及代码示例
- Node.js http2session.connecting用法及代码示例
- Node.js http.IncomingMessage.aborted用法及代码示例
- Node.js ServerHttp2Stream http2stream.respond([headers[, options]])用法及代码示例
- Node.js http2stream.setTimeout()用法及代码示例
- Node.js http.OutgoingMessage.removeHeader(name)用法及代码示例
- Node.js http.IncomingMessage.complete用法及代码示例
- Node.js http.validateHeaderName()用法及代码示例
- Node.js http.IncomingMessage.rawTrailers用法及代码示例
- Node.js http2session.setTimeout()用法及代码示例
注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 https.createServer([options][, requestListener])。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。