Advertisement
moonion_nashivan

Untitled

Mar 16th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const PORT = process.env.SERVER_PORT || 80;
  2.  
  3. const fs = require('fs');
  4. const https = require('https');
  5.  
  6. const express = require('express');
  7. const expressWs = require('express-ws');
  8.  
  9. // const Kenwood = require('./libs/Kenwood');
  10.  
  11.  
  12. const privateKey = fs.readFileSync('keys/remote_wahgo_com.key', 'utf8');
  13. const certificate = fs.readFileSync('keys/remote_wahgo_com.crt', 'utf8');
  14.  
  15. const app = express();
  16.  
  17. const httpsServer = https.createServer({key: privateKey, cert: certificate}, app);
  18. expressWs(app, httpsServer);
  19.  
  20.  
  21. const getIndex = (req, res) =>{
  22.     res.sendFile('/usr/app/public/index.html');
  23. }
  24.  
  25.  
  26. app.ws('/', function (ws, req) {
  27.  
  28.     ws.on('message', function (msg) {
  29.         console.log(msg);
  30.     });
  31. });
  32.  
  33. app.get('/', getIndex);
  34. app.get('/index.html', getIndex);
  35. app.use(express.static('/usr/app/public'));
  36. app.get('*', getIndex);
  37.  
  38.  
  39. httpsServer.listen(PORT, function () {
  40.     console.log('Server running on port ' + PORT + '.');
  41. });
  42.  
  43.  
  44. // const port = new Kenwood({dev:'/dev/tty-usbserial1'});
  45. // port.on('onZoneChannelData', console.log);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement