Guest User

JS2

a guest
Oct 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const https = require('https');
  3. const websocket = require('ws');
  4.  
  5. class Server {
  6.     constructor(options) {
  7.         console.log('[#] Initializing services on port %d...',  options.port);
  8.         this.initHttpsServer(options);
  9.         this.initWebsocketServer();
  10.     }
  11.  
  12.     initHttpsServer(options) {
  13.         this.httpServer = new https.createServer(options, function (request, response) {
  14.             response.writeHead(200, {'Content-Type': 'text/html'});
  15.             response.end();
  16.         });
  17.         this.httpServer.listen(options.port);
  18.     }
  19.  
  20.     initWebsocketServer() {
  21.         this.wsServer =  new websocket.Server(this.httpServer);
  22.     }
  23. }
  24.  
  25. const options = {
  26.     port: 8080,
  27.     key: fs.readFileSync('keys/key.pem', 'utf8'),
  28.     cert: fs.readFileSync('keys/cert.pem', 'utf8'),
  29.     passphrase: 'test123'
  30. };
  31. var server = new Server(options);
Advertisement
Add Comment
Please, Sign In to add comment