@cocreate/server 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## [1.1.1](https://github.com/CoCreate-app/CoCreate-server/compare/v1.1.0...v1.1.1) (2024-01-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * return if ssl false ([500e7c7](https://github.com/CoCreate-app/CoCreate-server/commit/500e7c7898f3a3a5ecc676ca68cd105cc1f29a6f))
7
+
8
+ # [1.1.0](https://github.com/CoCreate-app/CoCreate-server/compare/v1.0.2...v1.1.0) (2024-01-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update server object properties ([762b209](https://github.com/CoCreate-app/CoCreate-server/commit/762b209ffbb22ebf9bb992d14f96eeeac2391bda))
14
+
15
+
16
+ ### Features
17
+
18
+ * bumped CoCreate dependencies to their latest versions ([e6f76a5](https://github.com/CoCreate-app/CoCreate-server/commit/e6f76a57be9e4581c82fcf3e8e57768df35dfcd8))
19
+
1
20
  ## [1.0.2](https://github.com/CoCreate-app/CoCreate-server/compare/v1.0.1...v1.0.2) (2024-01-04)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/server",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "An intergration with Server and CoCreateJS.",
5
5
  "keywords": [
6
6
  "server",
@@ -45,6 +45,6 @@
45
45
  },
46
46
  "main": "./src/index.js",
47
47
  "dependencies": {
48
- "@cocreate/acme": "^1.0.0"
48
+ "@cocreate/acme": "^1.1.3"
49
49
  }
50
50
  }
package/src/index.js CHANGED
@@ -1,42 +1,38 @@
1
- const Https = require('https');
2
1
  const Http = require('http');
3
- const fs = require('fs');
2
+ const Https = require('https');
4
3
  const tls = require('tls');
5
4
  const acme = require('@cocreate/acme')
5
+ const fs = require('fs');
6
6
 
7
7
  let server = {
8
- acme: new acme(), // Initially an empty object or some placeholder functionality
9
-
10
- loadCertificates(domain) {
11
- try {
12
- return {
13
- key: fs.readFileSync(`/etc/certificates/${domain}/private-key.pem`),
14
- cert: fs.readFileSync(`/etc/certificates/${domain}/fullchain.pem`),
15
- };
16
- } catch (error) {
17
- console.error("Error loading certificates for domain:", domain);
18
- throw error; // Or handle it by returning default certificates
19
- }
20
- },
8
+ acme: new acme(),
9
+ http: Http.createServer(),
10
+ https: Https.createServer({ SNICallback: sniCallback })
11
+ };
21
12
 
22
- async sniCallback(domain, cb) {
23
- try {
24
- console.log('sni')
25
- await server.acme.checkCertificate(domain); // Referencing `this.acme`
13
+ function loadCertificates(domain) {
14
+ try {
15
+ return {
16
+ key: fs.readFileSync(`/etc/certificates/${domain}/private-key.pem`),
17
+ cert: fs.readFileSync(`/etc/certificates/${domain}/fullchain.pem`),
18
+ };
19
+ } catch (error) {
20
+ console.error("Error loading certificates for domain:", domain);
21
+ throw error; // Or handle it by returning default certificates
22
+ }
23
+ }
26
24
 
27
- const sslContext = tls.createSecureContext(server.loadCertificates(domain));
25
+ async function sniCallback(domain, cb) {
26
+ try {
27
+ console.log('sni')
28
+ if (await server.acme.checkCertificate(domain)) {
29
+ const sslContext = tls.createSecureContext(loadCertificates(domain));
28
30
  cb(null, sslContext);
29
- } catch (error) {
30
- console.error("Error in SNI callback for domain:", domain, error);
31
- cb(error); // handle error or use default context
32
- }
33
- },
34
-
35
- https: null, // Will be set after defining `sniCallback`
36
- http: Http.createServer()
37
- };
38
-
39
- // Creating the HTTPS server with the SNI callback
40
- server.https = Https.createServer({ SNICallback: server.sniCallback });
31
+ } else return
32
+ } catch (error) {
33
+ console.error("Error in SNI callback for domain:", domain, error);
34
+ cb(error); // handle error or use default context
35
+ }
36
+ }
41
37
 
42
38
  module.exports = server;