try to add parameter for localPath

This commit is contained in:
Dobromir Popov
2021-04-30 23:21:00 +03:00
parent b99b1f07d0
commit 7740770ace
9 changed files with 38 additions and 36 deletions

View File

@@ -113,7 +113,7 @@
}
chart.render();
$.getJSON("/n/dht", function(data){
$.getJSON(localPath + "/dht", function(data){
if(data && data.dht){
chart.title.set("text", "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
}else {
@@ -122,7 +122,7 @@
});
}
$.getJSON("/n/dht/A23_DHT", addData);
$.getJSON(localPath+ "/dht/A23_DHT", addData);
}
</script>

View File

@@ -76,22 +76,22 @@ app.get('/login',
});
app.post('/login',
passport.authenticate('local', { failureRedirect: '/n/login' }),
passport.authenticate('local', { failureRedirect: config.localPath+ '/login' }),
function(req, res) {
res.redirect('/n/');
res.redirect(config.localPath+ '/');
});
app.get('/logout',
function(req, res){
req.logout();
res.redirect('/n/');
res.redirect(config.localPath+ '/');
});
app.get('/accontrol',
// passport.authenticate('local', {
// failureRedirect: '/n/login' ,
// successRedirect: '/n/accontrol'}),
require('connect-ensure-login').ensureLoggedIn('/n/login'),
// failureRedirect: config.localPath+ '/login' ,
// successRedirect: config.localPath+ '/accontrol'}),
require('connect-ensure-login').ensureLoggedIn(config.localPath+ '/login'),
function(req, res){
res.render('accontrol', { user: req.user });
});

View File

@@ -7,6 +7,7 @@ const util = require('util');
var app = require('express')();
var db = require('./db');
var config = require('./setup_const');
var passport = require('passport');
var Strategy = require('passport-local').Strategy;
var CookieStrategy = require('passport-cookie').Strategy;
@@ -14,13 +15,13 @@ var CookieStrategy = require('passport-cookie').Strategy;
var session = require('express-session');
const cookierParser = require('cookie-parser');
var ensureLoggedIn = require("connect-ensure-login").ensureLoggedIn("/n/login");
var ensureLoggedIn = require("connect-ensure-login").ensureLoggedIn(config.localPath + "/login");
module.exports = {
ensureLoggedIn_Orig: ensureLoggedIn,
ensureLoggedIn_P: function (req, res, next){passport.authenticate('local', {
successRedirect: '/n/accontrol',
failureRedirect: '/n/login' })},
successRedirect: config.localPath + '/accontrol',
failureRedirect: config.localPath + '/login' })},
passport: passport,
ensureLoggedIn_New: function (req, res, next) {
if (req.isAuthenticated()) {
@@ -122,8 +123,8 @@ module.exports = {
app.post('/login',
passport.authenticate('local', {
successRedirect: '/n/accontrol',
failureRedirect: '/n/login' }),
successRedirect: config.localPath + '/accontrol',
failureRedirect: config.localPath + '/login' }),
// authenticated user.
function(req, res) {
console.log("logged in. session:" + req.session);
@@ -133,7 +134,7 @@ module.exports = {
app.get('/logout', function(req, res){
req.logout();
res.redirect('/n/login');
res.redirect(config.localPath + '/login');
});
return app;

View File

@@ -2,13 +2,14 @@ var GardenIP = '192.168.0.18';
var AcIP = '192.168.1.143';
var HouseDhtIP = '192.168.1.126';
var HomeControllerMQTT = '192.168.0.10'; //GW02
var localPath = "/n";
module.exports = {
GardenIP: '192.168.0.18',
AcIP : '192.168.1.143',
HouseDhtIP : '192.168.1.126',
HomeControllerMQTT : '192.168.0.10',
localPath : "/n",
foo: function () {
// whatever
},

View File

@@ -1,7 +1,7 @@
<h2>AC Control for <% if (model.user) {model.user.username; } %></h2>
<h4 id="current">Retrieving current conditions...</h4>
<!-- class="form-inline" -->
<form id="accontrol" action="/n/accontrol" method="POST">
<form id="accontrol" action= config.localPath + "/accontrol" method="POST">
<div class="form-group ">
<input type='checkbox' name='power' <%= model.data.power|true ? "checked" : "" %> data-toggle='toggle'
data-style='android' data-on='ON' data-off='Off' />
@@ -34,7 +34,7 @@ INFO:
<%- contentFor('head') %>
<script>
const url = 'wss://iot.d-popov.com/n/ws'
const url = 'wss://iot.d-popov.com' + config.localPath + '/ws'
const connection = new WebSocket(url)
connection.onopen = (d) => {
console.log(`WebSocket error: ${d}`)
@@ -57,7 +57,7 @@ INFO:
<script>
window.onload = function () {
$.getJSON("/n/dht?e=now", function(data){
$.getJSON(config.localPath + "/dht?e=now", function(data){
if(data && data.dht){
$('#current').text( "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH. Dew point : " + data.dht.dew + "°C" );
}else {

View File

@@ -145,7 +145,7 @@
}
chart.render();
$.getJSON("/n/dht?e=now", function(data){
$.getJSON(config.localPath + "/dht?e=now", function(data){
if(data && data.dht){
chart.title.set("text", "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
}else {
@@ -154,8 +154,8 @@
});
}
$.getJSON("/n/device/A23_DHT/7", addData);
$.getJSON("/n/device/A23_Garden_Humidity/7", addData);
$.getJSON(config.localPath + "/device/A23_DHT/7", addData);
$.getJSON(config.localPath + "/device/A23_Garden_Humidity/7", addData);
}
</script>

View File

@@ -20,11 +20,11 @@
Period
</button>
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
<a class="dropdown-item" href="/n/garden/1">Day</a>
<a class="dropdown-item" href="/n/garden/2">2 Days</a>
<a class="dropdown-item" href="/n/garden/7">Week</a>
<a class="dropdown-item" href="/n/garden/30">Month</a>
<a class="dropdown-item" href="/n/garden/91">Quarter</a>
<a class="dropdown-item" href=config.localPath + "/garden/1">Day</a>
<a class="dropdown-item" href=config.localPath + "/garden/2">2 Days</a>
<a class="dropdown-item" href=config.localPath + "/garden/7">Week</a>
<a class="dropdown-item" href=config.localPath + "/garden/30">Month</a>
<a class="dropdown-item" href=config.localPath + "/garden/91">Quarter</a>
</div>
</div>
</div>
@@ -224,10 +224,10 @@
chart.render();
}
$.getJSON("/n/device/A23_DHT/<%= model.days ? model.days : '7' %>", addData);
$.getJSON("/n/device/A23_Garden_dht/<%= model.days ? model.days : '7' %>", addData);
$.getJSON(config.localPath + "/device/A23_DHT/<%= model.days ? model.days : '7' %>", addData);
$.getJSON(config.localPath + "/device/A23_Garden_dht/<%= model.days ? model.days : '7' %>", addData);
setTimeout(function(){
$.getJSON("/n/dht?e=now", function(data){
$.getJSON(config.localPath + "/dht?e=now", function(data){
if(data && data.dht){
$("#now").text("In A23 currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
}else {
@@ -236,7 +236,7 @@
});
},5000);
$("#water").on("click", function(){$.ajax({url:"/n/water?t="+$("#waterTime").val()});});
$("#waterStop").on("click", function(){$.ajax({url:"/n/waterStop"});});
$("#water").on("click", function(){$.ajax({url:config.localPath + "/water?t="+$("#waterTime").val()});});
$("#waterStop").on("click", function(){$.ajax({url:config.localPath + "/waterStop"});});
}
</script>

View File

@@ -1,4 +1,4 @@
<form action="/n/login" method="post">
<form action=config.localPath+ "/login" method="post">
<div class="form-group">
<label>Username:</label>
<input type="text" name="username" class="form-control" />

View File

@@ -1,6 +1,6 @@
<a href="/n/accontrol" >control</a>
<a href="/n/logout" >log out</a>
<a href="/n/chart"> chart</a>
<a href="/n/garden"> garden</a>
<a href=config.localPath + "/accontrol" >control</a>
<a href=config.localPath + "/logout" >log out</a>
<a href=config.localPath + "/chart"> chart</a>
<a href=config.localPath + "/garden"> garden</a>