Switching server-side scripts over to coffeescript

This commit is contained in:
Patrick McDonagh
2016-03-24 18:30:12 -05:00
parent d9deeaa73b
commit 8b0aa91dea
2 changed files with 0 additions and 1723 deletions

191
app.js
View File

@@ -1,191 +0,0 @@
var DBTYPE = 'SQLite'; // OR "MySQL"
var express = require('express'),
path = require('path'),
fs = require('fs'),
//favicon = require('serve-favicon'),
logger = require('morgan'),
methodOverride = require('method-override'),
bodyParser = require('body-parser'),
errorHandler = require('errorhandler');
var app = express();
var json;
/**
* Configuration
*/
if (DBTYPE == "MySQL"){
var mysql = require('mysql');
var db_config = {
host: 'localhost',
user: 'website',
password: 'henrypump'
};
var handleDisconnect = function () {
console.log("Handling db disconnect gracefully");
app.locals.connection = mysql.createConnection(db_config);
app.locals.connection.connect(function (err) {
if (err) {
console.log('error when connecting to db:', err);
setTimeout(handleDisconnect, 2000);
}
});
app.locals.connection.on('error', function (err) {
console.log('db error', err);
if (err.code === 'PROTOCOL_CONNECTION_LOST') {
handleDisconnect();
} else {
throw err;
}
});
};
handleDisconnect();
json = require('./routes/json.js');
}
if (DBTYPE == "SQLite"){
json = require('./routes/json_sqlite.js');
}
app.set('port', process.env.PORT || 80);
app.set('views', path.join(__dirname, 'views'));
app.engine('.html', require('ejs').renderFile);
app.set('view engine', 'html');
//app.use(favicon(__dirname + '/public/img/favicon.ico'));
app.use(logger('dev'));
app.use(methodOverride());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
//app.use(express["static"](path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
/**
* Routes
*/
//index = require('./routes/index.js');
var angular = function(req, res) {
res.render('angularIndex');
};
app.get('/json/all/:date', json.allCards);
app.get('/json/page/:date/:page/:numPerPage', json.filePage);
app.get('/json/count/:date', json.countDateFiles);
app.get('/json/latest/:num', json.cardLatestX);
app.get('/json/latestCard', json.latestCardData);
app.get('/json/latest', json.cardLatestX);
app.get('/json/all', json.allDates);
app.get('/json/between/:start/:end', json.findBetweenDateTime);
app.get('/json/byID/:date/:card_id', json.getCardByCardID);
app.get('/json/card/:id', json.singleCard);
app.get('/csv/:id', json.cardCSV);
app.get('/json/status', json.status);
app.get('/json/setup', json.getSetup);
app.get('/json/totals', json.getCurrentTotals);
// -- Gauge-Off Data -- //
app.get('/json/history/all', json.historyAll);
app.get('/json/history', json.historyLatest);
// -- Well Test Data -- //
//app.get('/json/well_test/all', json.wellTestAll);
//app.get('/json/well_test', json.wellTestLatest);
// -- Event List -- //
app.get('/json/event_list/all', json.eventListAll);
app.get('/json/event_list/:numEvents', json.eventList);
app.get('/json/event_list', json.eventList);
// -- Well Configuration Backups -- //
app.get('/json/backups/:file', json.parseWellBackup);
app.get('/json/backups', json.getWellBackups);
// -- Tag Data -- //
app.get('/json/tags/get/status', json.statusTagData);
app.get('/json/tags/get/:tagName', json.getTagValue);
app.get('/json/tags/set/:tagName/:value/:mode', json.setTagValue);
app.get('/json/tags/set/:tagName/:value', json.setTagValue);
// -- Firmware Updating -- //
app.get('/json/maint/updateFiles/:force', json.updateFiles);
app.get('/json/maint/updateFiles', json.updateFiles);
// -- Fluid Shots -- //
app.get('/json/fluid_shot/get/deleted', json.getDeletedFluidShots);
app.get('/json/fluid_shot/get', json.getFluidShots);
app.post('/json/fluid_shot/post', json.postFluidShot);
app.post('/json/fluid_shot/delete', json.deleteFluidShot);
app.post('/json/fluid_shot/undelete', json.undeleteFluidShot);
app.post('/json/fluid_shot/update', json.updateFluidShot);
//-- Well Tests -- //
app.get('/json/well_test/get/deleted', json.getDeletedWellTests);
app.get('/json/well_test/get', json.getWellTests);
app.post('/json/well_test/post', json.postWellTest);
app.post('/json/well_test/delete', json.deleteWellTest);
app.post('/json/well_test/undelete', json.undeleteWellTest);
app.post('/json/well_test/update', json.updateWellTest);
// -- Notes -- //
app.get('/json/notes/get/types', json.getNoteTypes);
app.get('/json/notes/get/deleted', json.getDeletedNotes);
app.get('/json/notes/get', json.getNotes);
app.post('/json/notes/post', json.postNote);
app.post('/json/notes/delete', json.deleteNote);
app.post('/json/notes/undelete', json.undeleteNote);
app.post('/json/notes/update', json.updateNote);
// -- Python Scripts -- //
app.get('/json/pythonStatus', json.checkPythonScripts);
app.get('/json/pythonRestart', json.restartPythonScripts);
app.get('/json/:folder/:file', json.singleCardOldway);
app.get('/json/:folder/:file/taper', json.taper);
app.post('/json/cards', json.multipleCards);
app.post('/setup', json.updateSetup);
//-- Tag Values -- //
app.get('/json/tagvalues', json.getTagValues);
app.get('*', angular);
/**
* Start Server
*/
connectionsArray = [];
s_port = 3000;
var server = app.listen(s_port, function () {
var host = server.address().address;
var port = server.address().port;
console.log('POConsole listening at http://%s:%s', host, port);
console.log("Database Type is %s", DBTYPE);
});
// app.listen(port), function() {
// console.log('Listening on port ' + port);
// }
//
// io = require('socket.io').listen();
//
// io.sockets.on('connection', function(socket) {
// console.log('Number of connections:' + connectionsArray.length);
// socket.on('disconnect', function() {
// var socketIndex;
// socketIndex = connectionsArray.indexOf(socket);
// console.log('socket = ' + socketIndex + ' disconnected');
// if (socketIndex >= 0) {
// connectionsArray.splice(socketIndex, 1);
// }
// });
// console.log('A new socket is connected!');
// connectionsArray.push(socket);
// });

File diff suppressed because it is too large Load Diff