@cocreate/server 1.0.2 → 1.1.0

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,15 @@
1
+ # [1.1.0](https://github.com/CoCreate-app/CoCreate-server/compare/v1.0.2...v1.1.0) (2024-01-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update server object properties ([762b209](https://github.com/CoCreate-app/CoCreate-server/commit/762b209ffbb22ebf9bb992d14f96eeeac2391bda))
7
+
8
+
9
+ ### Features
10
+
11
+ * bumped CoCreate dependencies to their latest versions ([e6f76a5](https://github.com/CoCreate-app/CoCreate-server/commit/e6f76a57be9e4581c82fcf3e8e57768df35dfcd8))
12
+
1
13
  ## [1.0.2](https://github.com/CoCreate-app/CoCreate-server/compare/v1.0.1...v1.0.2) (2024-01-04)
2
14
 
3
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/server",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
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,39 @@
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));
28
- 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
- },
25
+ async function sniCallback(domain, cb) {
26
+ try {
27
+ console.log('sni')
28
+ await server.acme.checkCertificate(domain);
34
29
 
35
- https: null, // Will be set after defining `sniCallback`
36
- http: Http.createServer()
37
- };
30
+ const sslContext = tls.createSecureContext(loadCertificates(domain));
31
+ cb(null, sslContext);
38
32
 
39
- // Creating the HTTPS server with the SNI callback
40
- server.https = Https.createServer({ SNICallback: server.sniCallback });
33
+ } catch (error) {
34
+ console.error("Error in SNI callback for domain:", domain, error);
35
+ cb(error); // handle error or use default context
36
+ }
37
+ }
41
38
 
42
39
  module.exports = server;