@cocreate/server 1.0.1 → 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,22 @@
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
+
13
+ ## [1.0.2](https://github.com/CoCreate-app/CoCreate-server/compare/v1.0.1...v1.0.2) (2024-01-04)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * add '@cocreate/acme' ([73557b9](https://github.com/CoCreate-app/CoCreate-server/commit/73557b97d0a8f47d5cbb2b0b6f66dc87b5aa7a29))
19
+
1
20
  ## [1.0.1](https://github.com/CoCreate-app/CoCreate-server/compare/v1.0.0...v1.0.1) (2024-01-02)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/server",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "An intergration with Server and CoCreateJS.",
5
5
  "keywords": [
6
6
  "server",
@@ -43,5 +43,8 @@
43
43
  "type": "GitHub Sponsors ❤",
44
44
  "url": "https://github.com/sponsors/CoCreate-app"
45
45
  },
46
- "main": "./src/index.js"
46
+ "main": "./src/index.js",
47
+ "dependencies": {
48
+ "@cocreate/acme": "^1.1.3"
49
+ }
47
50
  }
package/src/index.js CHANGED
@@ -1,36 +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');
4
+ const acme = require('@cocreate/acme')
5
+ const fs = require('fs');
6
+
7
+ let server = {
8
+ acme: new acme(),
9
+ http: Http.createServer(),
10
+ https: Https.createServer({ SNICallback: sniCallback })
11
+ };
5
12
 
6
- // Load certificates or handle them dynamically via SNI
7
13
  function loadCertificates(domain) {
8
14
  try {
9
15
  return {
10
- key: fs.readFileSync(`certificates/${domain}/private.key`),
11
- cert: fs.readFileSync(`certificates/${domain}/certificate.crt`),
16
+ key: fs.readFileSync(`/etc/certificates/${domain}/private-key.pem`),
17
+ cert: fs.readFileSync(`/etc/certificates/${domain}/fullchain.pem`),
12
18
  };
13
19
  } catch (error) {
14
20
  console.error("Error loading certificates for domain:", domain);
15
- throw error; // Or handle it by returning default certificates
21
+ throw error; // Or handle it by returning default certificates
16
22
  }
17
23
  }
18
24
 
19
- function sniCallback(domain, cb) {
25
+ async function sniCallback(domain, cb) {
20
26
  try {
27
+ console.log('sni')
28
+ await server.acme.checkCertificate(domain);
29
+
21
30
  const sslContext = tls.createSecureContext(loadCertificates(domain));
22
31
  cb(null, sslContext);
32
+
23
33
  } catch (error) {
24
34
  console.error("Error in SNI callback for domain:", domain, error);
25
- cb(error); // handle error or use default context
35
+ cb(error); // handle error or use default context
26
36
  }
27
37
  }
28
38
 
29
- // Create HTTPS server
30
- const https = Https.createServer({ SNICallback: sniCallback });
31
-
32
- // Create HTTP server
33
- const http = Http.createServer();
34
-
35
- module.exports = { https, http };
36
-
39
+ module.exports = server;