Skip to content

Commit 49631de

Browse files
authored
Use Config File instead of Arguments (#18)
server-ssl.js - [x] configuration file instead of arguments
1 parent c7326de commit 49631de

File tree

6 files changed

+195
-130
lines changed

6 files changed

+195
-130
lines changed

README.md

Lines changed: 50 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
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

97
Designed 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

1515
The easiest usage would be to serve a website:
1616

@@ -21,109 +21,82 @@ The easiest usage would be to serve a website:
2121
5. Run `node server-ssl.js`
2222
6. 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

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

8079
At 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

160132
The 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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "server-ssl",
33
"author": "FirstTimeEZ",
4-
"version": "43.0.2",
4+
"version": "44.0.1",
55
"description": "Configurable SSL Server that runs on Node.js which can be used for development or production and can create and renew Lets Encrypt Certificates automatically using ACME",
66
"main": "template; do not import; read the Getting Started of the README, maybe you want to use: lets-encrypt-acme-client",
77
"type": "module",

server-ssl.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ const HTTPS_SERVER = createServerHTTPS(STATE.loadDefaultSecureContext(), (req, r
4141

4242
STATE.startHttpChallengeListener(); // Lets Encrypt! HTTP-01 ACME Challenge Mixin - Always Redirects HTTP to HTTPS unless doing a ACME Challenge
4343

44-
let dnsProvider = null;
45-
46-
// dnsProvider = {
47-
// name: "Cloud Flare",
48-
// token: "apiTokenWithDnsEditPermission"
49-
// }
50-
51-
STATE.loadLetsEncryptAcmeDaemon(() => { STATE.loadNewSecureContext(HTTPS_SERVER); }, dnsProvider);
44+
STATE.loadLetsEncryptAcmeDaemon(() => { STATE.loadNewSecureContext(HTTPS_SERVER); });
5245
// ^^ Update Certificates Callback
5346
STATE.checkNodeForUpdates(); // Check Node.js version

server-ssl.sc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
portHttps :: 443
2+
portHttp :: 80
3+
4+
certificate :: "certificate.pem"
5+
private-key :: "private-key.pem"
6+
7+
websiteRoot :: "wwwroot"
8+
entryPage :: "index.html"
9+
errorRoot :: "error"
10+
11+
noCheckNodeVersion :: false
12+
13+
useLetsEncrypt :: false
14+
domains :: ["ssl.boats","www.ssl.boats"]
15+
generateCertAnyway :: false
16+
useStaging :: false
17+
18+
useDnsProvider :: false
19+
providerName :: "Cloud Flare"
20+
providerToken :: "apiTokenWithDnsEditPermission"
21+
providerZone :: ""

0 commit comments

Comments
 (0)