22
33# server-ssl.js
44
5- Configurable ` SSL Server ` that runs on [ ` Node.js ` ] ( https://nodejs.org/en ) which can be used for development or production
6-
7- Create and renew ` Lets Encrypt Certificates ` automatically using ` ACME ` using ` DNS-01 ` with supported providers or ` HTTP-01 `
5+ [ ` Node.js ` ] ( https://nodejs.org/en ) server that is ` SSL ` by default that can be used for development or production
86
97Designed to get out of your way so you can still change _ anything_
108
11- --------
9+ Creates and renews ` Lets Encrypt Certificates ` automatically using ` ACME `
10+
11+ If you use ` CloudFlare ` you can get ` Wildcard Certificates `
1212
13- ### Getting Started
13+ ## Getting Started
1414
1515The easiest usage would be to serve a website:
1616
@@ -21,109 +21,82 @@ The easiest usage would be to serve a website:
21215 . Run ` node server-ssl.js `
22226 . View your website at ` https://localhost `
2323
24- [ ![ ] ( https://i.imgur.com/0IVqrfn .gif )] ( https://github.com/FirstTimeEZ/server-ssl/archive/refs/heads/main.zip )
24+ ![ ] ( https://i.imgur.com/ZYXoLMy .gif )
2525
26- The default page/config is a simple [ ` API ` ] ( https://github.com/FirstTimeEZ/simple-api-router ) that serves and displays the ` time `
26+ You can also use different kinds of ` Lets Encrypt! ` certificates, see configuration below.
2727
28- [ ![ ] ( https://i.imgur.com/DEbJVUq.png )] ( https://github.com/FirstTimeEZ/server-ssl/archive/refs/heads/main.zip )
28+ ![ ] ( https://i.imgur.com/mQ4uaxL.gif )
2929
30- ### Advanced/Production Usage
3130
32- ` node server-ssl.js ` takes your arguments and starts the server
31+ The default page/config is a simple [ ` API ` ] ( https://github.com/FirstTimeEZ/simple-api-router ) that serves and displays the ` time `
3332
34- ```
35- # Start for production (Lets Encrypt!) with SAN Extension
36- node server-ssl.js --letsEncrypt --domains=['www.ssl.boats','ssl.boats']
37- ```
33+ [ ![ ] ( https://i.imgur.com/DEbJVUq.png )] ( https://github.com/FirstTimeEZ/server-ssl/archive/refs/heads/main.zip )
3834
39- [ ![ ] ( https://i.imgur.com/BT8EEWj.gif )] ( https://github.com/FirstTimeEZ/server-ssl/archive/refs/heads/main.zip )
35+ ## Advanced/Production Usage
4036
41- ### Optional Arguments
37+ ` server-ssl.js ` has a configuration file called ` server-ssl.sc ` that contains all the options you can change
4238
43- ` server-ssl.js ` has some optional arguments you can use in production if the defaults aren't enough.
39+ #### Default Configuration ` (server-ssl.sc) `
40+
41+ ```
42+ portHttps :: 443 // The port number for HTTPS
43+ portHttp :: 80 // The port number for HTTP that will be redirected
4444
45- | Arguments/Flags | Description | Default Value |
46- | -------------------------| ----------------------------------| -----------------------|
47- | ` --port= ` | The port number for ` HTTPS ` | ` 443 ` |
48- | ` --portHttp= ` | The port number for HTTP that will be redirected | ` 80 ` |
49- | ` --cert= ` | The path to the ` SSL ` certificate file. | ` "certificate.pem" ` |
50- | ` --pk= ` | The path to the private key file for the ` SSL ` certificate. | ` "private-key.pem" ` |
51- | ` --site= ` | The directory for the website files | ` "wwwroot" ` |
52- | ` --error= ` | The directory for error messages (404,500) | ` "error" ` |
53- | ` --entry= ` | The page to use for the entry point | ` "index.html" ` |
45+ certificate :: "certificate.pem" // The path to the certificate file.
46+ private-key :: "private-key.pem" // The path to the private key for the certificate.
5447
55- All Arguments are case sensitive.
48+ websiteRoot :: "wwwroot" // The directory for the website files
49+ entryPage :: "index.html" // The page to use for the websites entry point
50+ errorRoot :: "error" // The directory for error messages (404,500)
5651
57- ### Use Lets Encrypt!
52+ noCheckNodeVersion :: false // True to skip checking Node.js version
5853
59- You can use ` Lets Encrypt ` to generate certificates.
54+ useLetsEncrypt :: false // Use Lets Encrypt! to generate a certificate
55+ domains :: ["ssl.boats","www.ssl.boats"] // Domains to generate the certificate for
56+ generateCertAnyway :: false // True to generate before the recommended time
57+ useStaging :: false // True to use the staging server to avoid rate limits
6058
61- Certificates are valid for ` 90 days ` but are renewed automatically sooner.
59+ useDnsProvider :: false // Use the DNS-01 Challenge to generate certificate
60+ providerName :: "Cloud Flare" // Name of supported DNS Provider
61+ providerToken :: "apiTokenWithDnsEditPermission" // API Token for DNS Provider
62+ providerZone :: "" // ZoneId for DNS Provider, may found automatically.
63+ ```
6264
63- The certificates will be changed automatically when they are updated, you don't need to do anything.
65+ #### Multiple Configuration Files
6466
65- | Automated Lets Encrypt! | Description |
66- | -------------------------| ----------------------------------|
67- | ` --letsEncrypt ` | ` Lets Encrypt! ` should be used to generate 90 day certificates automatically |
68- | ` --domains= ` | Domains to generate certificates for, this can not include wild cards, this should be an array. eg. ` --domains=['www.ssl.boats','ssl.boats'] ` |
69- | ` --generateAnyway ` | Certificates should always be generated when the server starts, this could get you rate limited, maybe use ` --staging ` |
70- | ` --staging ` | The ` Lets Encrypt! ` staging server should be used instead of production |
67+ You can create multiple configuration files and choose which one to load as an argument.
7168
7269```
73- node server-ssl.js --letsEncrypt --domains=['www.ssl.boats','ssl.boats']
70+ node server-ssl --config="server-ssl-staging.sc"
7471```
7572
76- ### Wild Card Certificates
73+ If no argument is provided the default configuration file is loaded. ` (server-ssl.sc) `
74+
75+ #### Generate Wild Card Certificates
7776
7877You can generate ` Wild Card Certificates ` if you use a supported ` DNS-01 ` provider
7978
8079At this present moment that is only ` Cloud Flare `
8180
82- ```
83- let dnsProvider = {
84- name: "Cloud Flare",
85- token: "apiTokenWithDnsEditPermission",
86- zone: "zoneId" // optional if it cant be found automatically.
87- }
88- ```
81+ ![ ] ( https://i.imgur.com/R132a6z.gif )
8982
90- Then to generate the certificate add a wildcard to the apex, eg. ` *.ssl.boats `
83+ #### Generate SAN Certificates
9184
92- `` `
93- --domains=['*.ssl.boats'] --staging
94- ```
85+ These certificates can have up to ` 50 ` sub-domains and no ` Wild Card `
86+
87+ You can generate ` Lets Encrypt Certificates ` with the ` SAN Extension ` using the ` HTTP-01 ` challenge
9588
96- [ ![ ] ( https://i.imgur.com/XA82Kt7.gif )] ( https://github.com/FirstTimeEZ/server-ssl/archive/refs/heads/main.zip )
89+ This is the default configuration.
9790
98- --------
91+ ![ ] ( https://i.imgur.com/VkOrZcX.gif )
9992
100- ### Always Redirect HTTP to HTTPS
93+ #### Always Redirects ` HTTP ` to ` HTTPS `
10194
10295` HTTP ` requests from end users are always redirected to ` HTTPS `
10396
10497` ACME Challenges ` transparently happen over ` HTTP ` to create/issue a new certificate
10598
106- --------
107-
108- ### Anything [ Node.js] ( https://nodejs.org/docs/latest/api/ ) can do..
109-
110- At the end of the day, this is just a [ ` Node.js ` ] ( https://nodejs.org/docs/latest/api/ ) server that sets up ` SSL ` automatically
111-
112- ```
113- const HTTPS_SERVER = createServerHTTPS(STATE.loadDefaultSecureContext(), (req, res) => {
114- // do whatever you like
115- })...
116- ```
117-
118- You can remove everything inside ` HTTPS_SERVER ` and do whatever you like.
119-
120- There are also helpers you can use in ` STATE `
121-
122- --------
123-
124- ### Default Layout
125-
126- This layout keeps the project organized and maintainable, separating error handling, website content, and server configuration.
99+ ## Default Layout
127100
128101```
129102/root
@@ -150,12 +123,11 @@ This layout keeps the project organized and maintainable, separating error handl
150123├── /wwwroot
151124│ └── index.html <---- Your website goes here
152125│
126+ ├── server-ssl.sc
153127└── server-ssl.js
154128```
155129
156- --------
157-
158- ### 404/500 Pages
130+ ## 404/500 Pages
159131
160132The server is configured to serve custom ` 404 ` and ` 500 ` error pages, instead of plain-text.
161133
@@ -165,19 +137,4 @@ Currently everything is treated like a `Server Error` except for `Not Found`
165137
166138[ ![ ] ( https://i.imgur.com/l8DMrQY.png )] ( https://github.com/FirstTimeEZ/server-ssl/archive/refs/heads/main.zip ) [ ![ ] ( https://i.imgur.com/mP2d4vi.png )] ( https://github.com/FirstTimeEZ/server-ssl/archive/refs/heads/main.zip )
167139
168- These pages will automatically select light/dark mode
169-
170- --------
171-
172- ### Bring Your Own SSL Certificate
173-
174- Convert your ` certificate ` and ` private key ` to ` PEM ` format and place them in the ` ssl ` folder
175-
176- ```
177- ├── /ssl
178- │ ├── /production <> staging
179- │ │ │
180- │ │ ├── ...
181- │ │ ├── private-key.pem <--- Your private key goes here
182- │ │ └── certificate.pem <--- Your certificate goes here
183- ```
140+ These pages will automatically select light/dark mode
0 commit comments