function createSecureServer
Usage in Deno
import { createSecureServer } from "node:http2";
createSecureServer(onRequestHandler?: (request: Http2ServerRequest,response: Http2ServerResponse,) => void): Http2SecureServer
Returns a tls.Server
instance that creates and manages Http2Session
instances.
const http2 = require('node:http2'); const fs = require('node:fs'); const options = { key: fs.readFileSync('server-key.pem'), cert: fs.readFileSync('server-cert.pem'), }; // Create a secure HTTP/2 server const server = http2.createSecureServer(options); server.on('stream', (stream, headers) => { stream.respond({ 'content-type': 'text/html; charset=utf-8', ':status': 200, }); stream.end('<h1>Hello World</h1>'); }); server.listen(8443);
optional
onRequestHandler: (request: Http2ServerRequest,response: Http2ServerResponse,) => void
See Compatibility API
createSecureServer(options: SecureServerOptions,onRequestHandler?: (request: Http2ServerRequest,response: Http2ServerResponse,) => void,): Http2SecureServer
options: SecureServerOptions
optional
onRequestHandler: (request: Http2ServerRequest,response: Http2ServerResponse,) => void