Skip to content

Instantly share code, notes, and snippets.

@Dobby89
Created November 1, 2021 08:57
Show Gist options
  • Save Dobby89/d574cf66403c48077198bdc0dd62c7b3 to your computer and use it in GitHub Desktop.
Save Dobby89/d574cf66403c48077198bdc0dd62c7b3 to your computer and use it in GitHub Desktop.
Generate SSL certificate for a folder

Taken from https://btholt.github.io/complete-intro-to-realtime/chat-with-http2-push and https://github.com/btholt/realtime-exercises/tree/main/http2/exercise

Use OpenSSL to generate the certificate

openssl req -new -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem
openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out server.crt

In your server file, create the server using the generated certificate and private key

import fs from "fs";
import http2 from "http2";
import path from "path";

const server = http2.createSecureServer({
  cert: fs.readFileSync(path.join(__dirname, "server.crt")),
  key: fs.readFileSync(path.join(__dirname, "key.pem")),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment