Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ In this app you are able to:
- Show list of buildings
- TODO: Select one from list
- TODO: View Building with all meters
- TODO: Each meter should have an the type of resource and the most recent reading.
- TODO: Each meter should have the type of resource and the most recent reading.
32 changes: 16 additions & 16 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ app.use(session({
resave: false,
saveUninitialized: true
}))

// Our custom app configs
// Contains Oauth2 key/secret
var config = require('./config.json');
Expand All @@ -31,20 +31,20 @@ var oauth2 = require('simple-oauth2')({
tokenPath: '/o/token/',
revocationPath: '/oauth2/revoke/'
});
// Authorization uri definition

// Authorization uri definition
var authorization_uri = oauth2.authCode.authorizeURL({
redirect_uri: 'http://localhost:3000/callback',
scope: 'read',
state: 'simple_state'
});
// Initial page redirecting to BuildingOS

// Initial page redirecting to BuildingOS
app.get('/auth', function (req, res) {
res.redirect(authorization_uri);
});
// Callback service parsing the authorization token and asking for the access token

// Callback service parsing the authorization token and asking for the access token
app.get('/callback', function (req, res) {
var code = req.query.code;
console.log('/callback');
Expand All @@ -53,12 +53,12 @@ app.get('/callback', function (req, res) {
code: code,
redirect_uri: 'http://localhost:3000/callback'
}, saveToken);

function saveToken(error, result) {
console.log('result', util.inspect(result));
console.log('error', util.inspect(error));
if (error) {
console.log('Access Token Error', error.message);
if (error) {
console.log('Access Token Error', error.message);
}
else {
// stash the token in the user session
Expand All @@ -70,7 +70,7 @@ app.get('/callback', function (req, res) {
}

});

// root of the app. Just has a link to kick off the auth process
app.get('/', function (req, res) {
res.render('index', { title: 'Hey', message: 'Hello there!'});
Expand All @@ -89,7 +89,7 @@ app.get('/buildings', function (req, res){
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
buildings = JSON.parse(body).data;
res.render('buildings', {title: 'Bulidings', buildings: buildings});
res.render('buildings', {title: 'Buildings', buildings: buildings});
}
});
});
Expand All @@ -113,12 +113,12 @@ app.get('/data', function (req, res){
var vals = {'a':1, 'b': 2, 'c': 3};
var ts_reading = {};
ts_reading[ts] = vals;
readings.push(ts_reading);
});
readings.push(ts_reading);
});

res.json({"data": readings});
});

// starting up the app and logging the address/port
var server = app.listen(3000, function () {

Expand Down