| 
									
										
										
										
											2019-11-01 04:12:40 -06:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function httpsWorker(glx) { | 
					
						
							| 
									
										
										
										
											2019-11-01 15:14:07 -06:00
										 |  |  |     // we need the raw https server
 | 
					
						
							|  |  |  |     var server = glx.httpsServer(); | 
					
						
							|  |  |  |     var WebSocket = require("ws"); | 
					
						
							|  |  |  |     var ws = new WebSocket.Server({ server: server }); | 
					
						
							|  |  |  |     ws.on("connection", function(ws, req) { | 
					
						
							|  |  |  |         // inspect req.headers.authorization (or cookies) for session info
 | 
					
						
							|  |  |  |         ws.send( | 
					
						
							|  |  |  |             "[Secure Echo Server] Hello!\nAuth: '" + | 
					
						
							|  |  |  |                 (req.headers.authorization || "none") + | 
					
						
							|  |  |  |                 "'\n" + | 
					
						
							|  |  |  |                 "Cookie: '" + | 
					
						
							|  |  |  |                 (req.headers.cookie || "none") + | 
					
						
							|  |  |  |                 "'\n" | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         ws.on("message", function(data) { | 
					
						
							|  |  |  |             ws.send(data); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-01 04:12:40 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 15:14:07 -06:00
										 |  |  |     // servers a node app that proxies requests to a localhost
 | 
					
						
							|  |  |  |     glx.serveApp(function(req, res) { | 
					
						
							|  |  |  |         res.setHeader("Content-Type", "text/html; charset=utf-8"); | 
					
						
							|  |  |  |         res.end("Hello, World!\n\n💚 🔒.js"); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-01 04:12:40 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var pkg = require("../../package.json"); | 
					
						
							|  |  |  | //require("greenlock-express")
 | 
					
						
							|  |  |  | require("../../") | 
					
						
							| 
									
										
										
										
											2019-11-01 15:14:07 -06:00
										 |  |  |     .init(function getConfig() { | 
					
						
							|  |  |  |         // Greenlock Config
 | 
					
						
							| 
									
										
										
										
											2019-11-01 04:12:40 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 15:14:07 -06:00
										 |  |  |         return { | 
					
						
							|  |  |  |             package: { name: "websocket-example", version: pkg.version }, | 
					
						
							|  |  |  |             maintainerEmail: "jon@example.com", | 
					
						
							|  |  |  |             cluster: false | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     .serve(httpsWorker); |