munrexio / yandex2mqtt

Bridge from Yandex Smart Home to MQTT
MIT License
107 stars 74 forks source link

Http #6

Open vladtsit opened 4 years ago

vladtsit commented 4 years ago

Просьба добавить в насторойках вариант использования http. Я буду превращать его в https самостоятельно на роутере. Я изменил 3-4 строки в коде и все заработало. Возможно, другим тоже понадобится.

RushOnline commented 2 years ago

чиркни, что менял, я тоже прячу за nginx

RushOnline commented 2 years ago

сделал так:

diff --git a/app.js b/app.js
index 2e9a3d3..f33366a 100644
--- a/app.js
+++ b/app.js
@@ -14,14 +14,9 @@ const mqtt = require('mqtt');
 const device = require('./device');
 const fs = require('fs');
 const app = express();
-const https = require('https');
-const privateKey = fs.readFileSync(config.https.privateKey, 'utf8');
-const certificate = fs.readFileSync(config.https.certificate, 'utf8');
-const credentials = {
-    key: privateKey,
-    cert: certificate
-};
-const httpsServer = https.createServer(credentials, app);
+const https = require('http');
+const httpsServer = https.createServer({}, app);
+
 global.devices = [];

 if (config.devices) {
@@ -74,7 +69,7 @@ app.get('/provider/v1.0/user/devices', routes.user.devices);
 app.post('/provider/v1.0/user/devices/query', routes.user.query);
 app.post('/provider/v1.0/user/devices/action', routes.user.action);
 app.post('/provider/v1.0/user/unlink', routes.user.unlink);
-httpsServer.listen(config.https.port);
+httpsServer.listen(config.http.port);

 function findDevIndex(arr, elem) {
diff --git a/config.js b/config.js
index d8c3d05..2409b41 100644
--- a/config.js
+++ b/config.js
@@ -7,10 +7,8 @@ module.exports = {
         password: ''
     },

-    https: {
-        privateKey: '/mnt/data/root/node-key2.pem',
-        certificate: '/mnt/data/root/munrexio.crt',
-        port: 443
+    http: {
+        port: 81
     },

     clients: [