Skip to content

Node.js server that is SSL by default that can be used for development or production and can create and renew Lets Encrypt Certificates automatically using ACME, including wildcard certificates

License

Notifications You must be signed in to change notification settings

FirstTimeEZ/server-ssl

Repository files navigation

server-ssl

Node.js server that is SSL by default that can be used for development or production

Designed to get out of your way so you can still change anything

Creates and renews Lets Encrypt Certificates automatically using ACME

If you use CloudFlare you can get Wildcard Certificates

Getting Started

The easiest usage would be to serve a website:

  1. Clone or Download the main branch and extract it somewhere
  2. Put your website in the website folder
  3. Open the server-ssl folder in Command Prompt or Git Bash
  4. Run npm install
  5. Run node server-ssl
  6. View your website at https://localhost

You can also use different kinds of Lets Encrypt! certificates, see configuration below.

The default page/config is a simple API that serves and displays the time

Advanced/Production Usage

server-ssl has a configuration file called server-ssl.sc that contains all the options you can change

Default Configuration (server-ssl.sc)

portHttps          :: 443                                // The port number for HTTPS
portHttp           :: 80                                 // The port number for HTTP that will be redirected

certificate        :: "certificate.pem"                  // The path to the certificate file.
private-key        :: "private-key.pem"                  // The path to the private key for the certificate.

websiteRoot        :: "wwwroot"                          // The directory for the website files
entryPage          :: "index.html"                       // The page to use for the websites entry point 
errorRoot          :: "error"                            // The directory for error messages (404,500)

noCheckNodeVersion :: false                              // True to skip checking Node.js version

useLetsEncrypt     :: false                              // Use Lets Encrypt! to generate a certificate
domains            :: ["ssl.boats","www.ssl.boats"]      // Domains to generate the certificate for
generateCertAnyway :: false                              // True to generate before the recommended time
useStaging         :: false                              // True to use the staging server to avoid rate limits

useDnsProvider     :: false                              // Use the DNS-01 Challenge to generate certificate
providerName       :: "Cloud Flare"                      // Name of supported DNS Provider
providerToken      :: "apiTokenWithDnsEditPermission"    // API Token for DNS Provider
providerZone       :: ""                                 // ZoneId for DNS Provider, may found automatically.

Multiple Configuration Files

You can create multiple configuration files and choose which one to load as an argument.

node server-ssl --config="server-ssl-staging.sc"

If no argument is provided the default configuration file is loaded. (server-ssl.sc)

Generate Wild Card Certificates

You can generate Wild Card Certificates if you use a supported DNS-01 provider

At this present moment that is only Cloud Flare

Generate SAN Certificates

These certificates can have up to 50 sub-domains and no Wild Card

You can generate Lets Encrypt Certificates with the SAN Extension using the HTTP-01 challenge

This is the default configuration.

Always Redirects HTTP to HTTPS

HTTP requests from end users are always redirected to HTTPS

ACME Challenges transparently happen over HTTP to create/issue a new certificate

Default Layout

/root
│
├── /error
│   ├── 404.html
│   └── 500.html
│
├── /ssl
│   ├── /production
│   │   │
│   │   ├── ...
│   │   ├── private-key.pem
│   │   └── certificate.pem
│   │
│   ├── /staging
│   │   │
│   │   ├── ...
│   │   ├── private-key.pem
│   │   └── certificate.pem
│   │
│   └── state.js
│
├── /wwwroot
│   └── index.html <---- Your website goes here
│
├── server-ssl.sc
└── server-ssl.js

404/500 Pages

The server is configured to serve custom 404 and 500 error pages, instead of plain-text.

Currently everything is treated like a Server Error except for Not Found

These pages will automatically select light/dark mode