Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Commented Certificate Chain Code
# Require the https/fs modules
# Akin to Apache's configuration directive:
# LoadModule ssl_module libexec/libssl.so
# (Apache's FS module is built in, I think)
https = require 'https'
fs = require 'fs'
# List the certificate chain files
# (with Apache you might put these 4 files into 1 file, called your certificate chain)
files = [
"EssentialSSLCA_2.crt"
"ComodoUTNSGCCA.crt"
"UTNAddTrustSGCCA.crt"
"AddTrustExternalCARoot.crt"
]
# Read these files (just like Apache does internally)
ca = (fs.readFileSync "/path/to/#{file}" for file in files)
# Specify the SSL configuration
# These are the equivalent of Apache's configuration directives:
# SSLCACertificateFile / SSLCertificateChainFile
# SSLCertificateKeyFile
# SSLCertificateFile
httpsOptions =
ca: ca
key: "/path/to/server.key"
cert: "/path/to/mydomain.crt"
# This is the thing that processes requests, i.e. this is the core of Apache.
requestHandler = (req, res) ->
res.writeHead 501
res.end()
# This creates a new instance of the HTTPS server, and then listens on localhost:443
# Akin to Apache's configuration directive:
# Listen 127.0.0.1:443
httpsServer = https.createServer httpsOptions, requestHandler
httpsServer.listen 443, "localhost"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment