Skip to content

Commit 1552ea3

Browse files
committed
server-ssl.js
📦[email protected] - [x] Implemented `DNS-01` Challenge - [x] Implemented `Cloud Flare DNS Provider`
1 parent 61372c1 commit 1552ea3

File tree

5 files changed

+47
-16
lines changed

5 files changed

+47
-16
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
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 and can create and renew `Lets Encrypt Certificates` automatically using `ACME`
5+
Configurable `SSL Server` that runs on [`Node.js`](https://nodejs.org/en) which can be used for development or production
66

7-
Designed to get out of your way so you can still change anything about `https.createServer`.
7+
Create and renew `Lets Encrypt Certificates` automatically using `ACME` using `DNS-01` with supported providers or `HTTP-01`
8+
9+
Designed to get out of your way so you can still change _anything_
810

911
--------
1012

@@ -70,6 +72,27 @@ The certificates will be changed automatically when they are updated, you don't
7072
```
7173
node server-ssl.js --letsEncrypt --domains=['www.ssl.boats','ssl.boats']
7274
```
75+
76+
### Wild Card Certificates
77+
78+
You can generate `Wild Card Certificates` if you use a supported `DNS-01` provider
79+
80+
At this present moment that is only `Cloud Flare`
81+
82+
```
83+
let dnsProvider = {
84+
name: "Cloud Flare",
85+
token: "apiTokenWithDnsEditPermission",
86+
zone: "zoneId" // optional if it cant be found automatically.
87+
}
88+
```
89+
90+
Then to generate the certificate add a wildcard to the apex, eg. `*.ssl.boats`
91+
92+
```
93+
--domains=['*.ssl.boats'] --staging
94+
```
95+
7396
--------
7497

7598
### Always Redirect HTTP to HTTPS

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
],
2727
"license": "Apache-2.0",
2828
"dependencies": {
29-
"base-acme-client": "^30.0.2",
30-
"lets-encrypt-acme-client": "^30.0.2",
29+
"base-acme-client": "^30.0.3",
30+
"lets-encrypt-acme-client": "^40.0.1",
3131
"simple-api-router": "^1.1.1",
3232
"simple-open-ssl": "^1.0.7"
3333
},

server-ssl.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ API.addEndpoint(new Endpoint("time", "GET", (req, res) => {
2424
}));
2525

2626
const HTTPS_SERVER = createServerHTTPS(STATE.loadDefaultSecureContext(), (req, res) => {
27+
//const host = req.headers.host; // e.g., api.example.com
2728
let route = undefined;
2829

2930
if (req.url === STATE.WEBSITE_ROOT) {
@@ -40,6 +41,13 @@ const HTTPS_SERVER = createServerHTTPS(STATE.loadDefaultSecureContext(), (req, r
4041

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

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

ssl/state.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ export const STATE = {
224224
console.log("Could not determine if Node.js version is recent");
225225
}
226226
},
227-
loadLetsEncryptAcmeDaemon: (certificateCallback) => {
227+
loadLetsEncryptAcmeDaemon: (certificateCallback, dnsProvider) => {
228228
STATE.optLetsEncrypt && STATE.optDomains !== null && (STATE.urlsArray = STATE.extractDomainsAnyFormat(STATE.optDomains));
229-
STATE.optLetsEncrypt && startLetsEncryptDaemon(STATE.urlsArray, STATE.__sslFolder, certificateCallback, STATE.optGenerateAnyway, STATE.optStaging);
229+
STATE.optLetsEncrypt && startLetsEncryptDaemon(STATE.urlsArray, STATE.__sslFolder, certificateCallback, STATE.optGenerateAnyway, STATE.optStaging, dnsProvider);
230230
},
231231
redirect: (res, req) => {
232232
res.writeHead(STATE.REDIRECT, { [STATE.REDIRECT_LOCATION]: `${STATE.HTTPS}${req.headers.host}${req.url}` });

0 commit comments

Comments
 (0)