@cocreate/server 1.0.1 → 1.0.2

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,10 @@
1
+ ## [1.0.2](https://github.com/CoCreate-app/CoCreate-server/compare/v1.0.1...v1.0.2) (2024-01-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add '@cocreate/acme' ([73557b9](https://github.com/CoCreate-app/CoCreate-server/commit/73557b97d0a8f47d5cbb2b0b6f66dc87b5aa7a29))
7
+
1
8
  ## [1.0.1](https://github.com/CoCreate-app/CoCreate-server/compare/v1.0.0...v1.0.1) (2024-01-02)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/server",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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.0.0"
49
+ }
47
50
  }
package/src/index.js CHANGED
@@ -2,35 +2,41 @@ const Https = require('https');
2
2
  const Http = require('http');
3
3
  const fs = require('fs');
4
4
  const tls = require('tls');
5
+ const acme = require('@cocreate/acme')
5
6
 
6
- // Load certificates or handle them dynamically via SNI
7
- function loadCertificates(domain) {
8
- try {
9
- return {
10
- key: fs.readFileSync(`certificates/${domain}/private.key`),
11
- cert: fs.readFileSync(`certificates/${domain}/certificate.crt`),
12
- };
13
- } catch (error) {
14
- console.error("Error loading certificates for domain:", domain);
15
- throw error; // Or handle it by returning default certificates
16
- }
17
- }
7
+ let server = {
8
+ acme: new acme(), // Initially an empty object or some placeholder functionality
18
9
 
19
- function sniCallback(domain, cb) {
20
- try {
21
- const sslContext = tls.createSecureContext(loadCertificates(domain));
22
- cb(null, sslContext);
23
- } catch (error) {
24
- console.error("Error in SNI callback for domain:", domain, error);
25
- cb(error); // handle error or use default context
26
- }
27
- }
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
+ },
28
21
 
29
- // Create HTTPS server
30
- const https = Https.createServer({ SNICallback: sniCallback });
22
+ async sniCallback(domain, cb) {
23
+ try {
24
+ console.log('sni')
25
+ await server.acme.checkCertificate(domain); // Referencing `this.acme`
31
26
 
32
- // Create HTTP server
33
- const http = Http.createServer();
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
+ },
34
34
 
35
- module.exports = { https, http };
35
+ https: null, // Will be set after defining `sniCallback`
36
+ http: Http.createServer()
37
+ };
36
38
 
39
+ // Creating the HTTPS server with the SNI callback
40
+ server.https = Https.createServer({ SNICallback: server.sniCallback });
41
+
42
+ module.exports = server;