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.
import http2 from 'node:http2';
import fs from '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<Http1Request extends IncomingMessage = IncomingMessage,Http1Response extends ServerResponse = ServerResponse,Http2Request extends Http2ServerRequest = Http2ServerRequest,Http2Response extends Http2ServerResponse = Http2ServerResponse,>(options: SecureServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,onRequestHandler?: (request: InstanceType<Http2Request>,response: InstanceType<Http2Response>,) => void,): Http2SecureServer<Http1Request, Http1Response, Http2Request, Http2Response>
Http1Request extends IncomingMessage = IncomingMessage
Http1Response extends ServerResponse = ServerResponse
Http2Request extends Http2ServerRequest = Http2ServerRequest
Http2Response extends Http2ServerResponse = Http2ServerResponse
optional
onRequestHandler: (request: InstanceType<Http2Request>,response: InstanceType<Http2Response>,) => void