Skip to content

Commit 2b03dd4

Browse files
author
Jeremy Tammik
committed
started added lmv viewer, read key and secret from environment variables
1 parent 5d96ab9 commit 2b03dd4

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "CompHoundWeb",
3-
"version": "0.0.22",
3+
"version": "0.0.23",
44
"description": "Cloud-based universal component and asset usage analysis, report and visualisation",
55
"main": "server.js",
66
"license": "MIT",
@@ -18,7 +18,8 @@
1818
"express": "*",
1919
"handlebars": "^4.0.2",
2020
"mongoose": "*",
21-
"mongoose-datatable": "^1.0.4"
21+
"mongoose-datatable": "^1.0.4",
22+
"view-and-data": "^1.0.0"
2223
},
2324
"engines": {
2425
"node": "0.10.x"

server.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,30 @@
99
//
1010
// Copyright 2015 by Jeremy Tammik, Autodesk Inc.
1111

12+
// Ensure that the View and Data API consumer
13+
// key and secret environment variables are set.
14+
15+
if( !process.env.COMPHOUND_CONSUMERKEY
16+
|| !process.env.COMPHOUND_CONSUMERSECRET ) {
17+
var msg = 'Please set the CompHound View and Data API '
18+
+ 'consumer key and secret environment variables '
19+
+ 'COMPHOUND_CONSUMERKEY and COMPHOUND_CONSUMERSECRET '
20+
+ 'before starting the server.';
21+
console.log( msg );
22+
throw new Error( msg );
23+
}
24+
25+
//console.log(
26+
// 'CompHound View and Data API consumer key and secret: '
27+
// + process.env.COMPHOUND_CONSUMERKEY + ' '
28+
// + process.env.COMPHOUND_CONSUMERSECRET );
29+
30+
// Read configuration settings.
31+
1232
var pkg = require( './package.json' );
1333
var config = require('./config.json');
1434

15-
// Mongo database stuff
35+
// Set up Mongo database.
1636

1737
var mongoose = require('mongoose');
1838

@@ -53,7 +73,7 @@ db.once( 'open', function() {
5373
+ ' database at ' + db.host
5474
+ ' established.' );
5575

56-
// Middleware
76+
// Set up web serveer middleware.
5777

5878
var path = require('path');
5979
var express = require('express');
@@ -72,20 +92,20 @@ db.once( 'open', function() {
7292
app.use( bodyParser.json({ limit: '1mb' }) );
7393
app.use( bodyParser.urlencoded({ extended: true, limit: '1mb' }) );
7494

75-
// REST API to populate mongo database
95+
// Define REST API to populate mongo database.
7696

7797
model = require( './model/instance' );
7898
require( './routes' )( app );
7999

80-
// Public HTML client access points
100+
// Public HTML client access points.
81101

82102
app.get( '/', function( request, response ) {
83103
response.send( 'CompHound cloud-based universal '
84104
+ 'component and asset usage analysis, report '
85105
+ 'and visualisation ' + pkg.version + '.\n' );
86106
});
87107

88-
// Just for fun, echo a message, if provided
108+
// Just for fun, echo a message, if provided.
89109

90110
app.get('/hello/:message', function (req, res) {
91111
res.send('CompHound: Hello! You sent me <b>'
@@ -118,6 +138,7 @@ db.once( 'open', function() {
118138
+ template_filename );
119139

120140
instances1_template = hb.compile(data);
141+
return 0;
121142
}
122143
);
123144

@@ -150,27 +171,29 @@ db.once( 'open', function() {
150171
//app.get('/www/datatable', function(req, res) {
151172
// res.render('index');
152173
//});
174+
153175
app.get('/datatable2', function(req, res) {
154176
res.sendFile(path.join(__dirname, 'public/datatable2.html'));
155177
});
156178
app.get('/www/data', function(req, res, next) {
157179
var options = { select: "bool" };
158-
model.dataTable(req.query, options, function(err, data) {
180+
model.dataTable( req.query, options, function(err, data) {
159181
//if (err) return next(err);
160182
if (err) return res.send(err);
161183
res.send(data);
184+
return 0;
162185
});
163186
});
164187

165-
// catch 404 and forward to error handler
188+
// Catch 404 and forward to error handler.
166189

167190
app.use(function(req, res, next) {
168191
var err = new Error('Not Found');
169192
err.status = 404;
170193
//next(err);
171194
});
172195

173-
// error handlers
196+
// Error handlers
174197

175198
// development error handler
176199
// will print stacktrace

0 commit comments

Comments
 (0)