mirror of
https://github.com/lasthead0/yandex2mqtt.git
synced 2025-08-08 09:01:00 +03:00
ESLint refactoring, remove bodyParser require
This commit is contained in:
28
app.js
28
app.js
@@ -9,7 +9,6 @@ const app = express();
|
|||||||
const https = require('https');
|
const https = require('https');
|
||||||
/* parsers */
|
/* parsers */
|
||||||
const cookieParser = require('cookie-parser');
|
const cookieParser = require('cookie-parser');
|
||||||
const bodyParser = require('body-parser');
|
|
||||||
/* error handler */
|
/* error handler */
|
||||||
const errorHandler = require('errorhandler');
|
const errorHandler = require('errorhandler');
|
||||||
/* seesion and passport */
|
/* seesion and passport */
|
||||||
@@ -26,17 +25,17 @@ app.set('view engine', 'ejs');
|
|||||||
app.set('views', path.join(__dirname, './views'));
|
app.set('views', path.join(__dirname, './views'));
|
||||||
app.use(express.static('views'));
|
app.use(express.static('views'));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(bodyParser.json({
|
app.use(express.json({
|
||||||
extended: false
|
extended: false,
|
||||||
}));
|
}));
|
||||||
app.use(bodyParser.urlencoded({
|
app.use(express.urlencoded({
|
||||||
extended: true
|
extended: true,
|
||||||
}));
|
}));
|
||||||
app.use(errorHandler());
|
app.use(errorHandler());
|
||||||
app.use(session({
|
app.use(session({
|
||||||
secret: 'keyboard cat',
|
secret: 'keyboard cat',
|
||||||
resave: false,
|
resave: false,
|
||||||
saveUninitialized: false
|
saveUninitialized: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
/* passport */
|
/* passport */
|
||||||
@@ -48,6 +47,7 @@ require('./auth');
|
|||||||
|
|
||||||
/* routers */
|
/* routers */
|
||||||
const {site: r_site, oauth2: r_oauth2, user: r_user, client: r_client} = require('./routes');
|
const {site: r_site, oauth2: r_oauth2, user: r_user, client: r_client} = require('./routes');
|
||||||
|
|
||||||
app.get('/', r_site.index);
|
app.get('/', r_site.index);
|
||||||
app.get('/login', r_site.loginForm);
|
app.get('/login', r_site.loginForm);
|
||||||
app.post('/login', r_site.login);
|
app.post('/login', r_site.login);
|
||||||
@@ -70,7 +70,7 @@ const privateKey = fs.readFileSync(config.https.privateKey, 'utf8');
|
|||||||
const certificate = fs.readFileSync(config.https.certificate, 'utf8');
|
const certificate = fs.readFileSync(config.https.certificate, 'utf8');
|
||||||
const credentials = {
|
const credentials = {
|
||||||
key: privateKey,
|
key: privateKey,
|
||||||
cert: certificate
|
cert: certificate,
|
||||||
};
|
};
|
||||||
const httpsServer = https.createServer(credentials, app);
|
const httpsServer = https.createServer(credentials, app);
|
||||||
httpsServer.listen(config.https.port);
|
httpsServer.listen(config.https.port);
|
||||||
@@ -99,22 +99,16 @@ global.mqttClient = mqtt.connect(`mqtt://${config.mqtt.host}`, {
|
|||||||
port: config.mqtt.port,
|
port: config.mqtt.port,
|
||||||
username: config.mqtt.user,
|
username: config.mqtt.user,
|
||||||
password: config.mqtt.password
|
password: config.mqtt.password
|
||||||
})
|
}).on('connect', () => { /* on connect event handler */
|
||||||
/* on connect event handler */
|
|
||||||
.on('connect', () => {
|
|
||||||
mqttClient.subscribe(subscriptions.map(pair => pair.topic));
|
mqttClient.subscribe(subscriptions.map(pair => pair.topic));
|
||||||
})
|
}).on('offline', () => { /* on offline event handler */
|
||||||
/* on offline event handler */
|
|
||||||
.on('offline', () => {
|
|
||||||
/* */
|
/* */
|
||||||
})
|
}).on('message', (topic, message) => { /* on get message event handler */
|
||||||
/* on get message event handler */
|
|
||||||
.on('message', (topic, message) => {
|
|
||||||
const subscription = subscriptions.find(sub => topic.toLowerCase() === sub.topic.toLowerCase());
|
const subscription = subscriptions.find(sub => topic.toLowerCase() === sub.topic.toLowerCase());
|
||||||
if (subscription == undefined) return;
|
if (subscription == undefined) return;
|
||||||
|
|
||||||
const {deviceId, instance} = subscription;
|
const {deviceId, instance} = subscription;
|
||||||
const ldevice = global.devices.find(d => d.data.id == deviceId);
|
const ldevice = global.devices.find(d => d.data.id == deviceId);
|
||||||
ldevice.updateState(`${message}`, instance);
|
ldevice.updateState(`${message}`, instance);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user