├── README.md ├── index.html ├── package.json └── server.js /README.md: -------------------------------------------------------------------------------- 1 | # :gun: polyGun-letsencrypt ![image](https://user-images.githubusercontent.com/1423657/31971779-a18416e0-b91d-11e7-8251-42d509d50640.png) 2 | *Simply start a secure [gun](https://github.com/amark/gun) server w/ LetsEncrypt SSL Certificates* 3 | 4 | #### Features 5 | * Fetch SSL certificates from LetsEncrypt 6 | * Automatically renew certificates 7 | * Forward all incoming HTTP requests to HTTPS 8 | 9 | ### Parameters 10 | * PEM_EMAIL: registration + notification email for LetsEncrypt 11 | * PEM_DOMAIN: domain name for certificate 12 | * PRODUCTION: boolean, false for staging only _(fake certificates)_ 13 | 14 | ## Usage 15 | #### Staging 16 | ``` 17 | PEM_EMAIL="your.name@some.domain" PEM_DOMAIN="gun.some.domain" nodejs server.js 18 | ``` 19 | 20 | #### Production 21 | ``` 22 | PEM_EMAIL="your.name@some.domain" PEM_DOMAIN="gun.some.domain" PRODUCTION="true" nodejs server.js 23 | ``` 24 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | GunDB Hello 6 | 13 | 14 | 15 | 16 |

GunDB Hello World

17 |

Open your web console

18 | 19 | 20 | 21 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "polyGun-letsencrypt", 3 | "version": "0.9.9", 4 | "description": "Simple HTTPS Gun server w/ LetsEncrypt support", 5 | "main": "server.js", 6 | "scripts": { 7 | "start": "node server.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "github.com/lmangani/polygun-letsencrypt" 12 | }, 13 | "keywords": [ 14 | "gun", 15 | "gunDB", 16 | "server", 17 | "setup", 18 | "realtime", 19 | "http", 20 | "https", 21 | "polyglot", 22 | "letsencrypt", 23 | "wss" 24 | ], 25 | "author": "Lorenzo Mangani ", 26 | "license": "MIT", 27 | "dependencies": { 28 | "auto-sni": "^2.3.2", 29 | "gun": "^0.2019.915" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | /* Self-Validating SSL GunDB */ 2 | /* using LetsEncrypt Certs */ 3 | 4 | var pem_email = process.env.PEM_EMAIL 5 | var pem_domain = process.env.PEM_DOMAIN 6 | var debug = process.env.PRODUCTION ? false : true; 7 | 8 | if (!pem_email||!pem_domain) { console.log('Missing key parameters! Exiting...'); process.exit(0); } 9 | if (debug) console.log('Staging Mode! No real certificated issued!'); 10 | 11 | var createServer = require("auto-sni"); 12 | const Gun = require("gun"); 13 | 14 | var app = function(req, res){ 15 | if(Gun.serve(req, res)){ return; } // filters gun requests! 16 | require('fs').createReadStream(require('path').join(__dirname, req.url)).on('error',function(){ // static files! 17 | res.writeHead(200, {'Content-Type': 'text/html'}); 18 | res.end(require('fs') 19 | .readFileSync(require('path') 20 | .join(__dirname, 'index.html') // or default to index 21 | )); 22 | }).pipe(res); // stream 23 | }; 24 | 25 | var server = createServer({ 26 | email: pem_email, // Emailed when certificates expire. 27 | agreeTos: true, // Required for letsencrypt. 28 | debug: debug, // Add console messages and uses staging LetsEncrypt server. (Disable in production) 29 | domains: [ pem_domain ], // List of accepted domain names. (You can use nested arrays to register bundles with LE). 30 | dir: "/etc/letsencrypt", // Directory for storing certificates. Defaults to "~/letsencrypt/etc" if not present. 31 | ports: { 32 | http: 80, // Optionally override the default http port. 33 | https: 443 // // Optionally override the default https port. 34 | } 35 | }, app); 36 | 37 | // Server is a "https.createServer" instance. 38 | server.once("listening", ()=> { 39 | var gun = Gun({ 40 | file: 'data.json', 41 | web: server 42 | }); 43 | 44 | // Sync everything 45 | gun.on('out', {get: {'#': {'*': ''}}}); 46 | console.log("Gun is ready to go."); 47 | }); 48 | --------------------------------------------------------------------------------