167 lines
5.2 KiB
CoffeeScript
167 lines
5.2 KiB
CoffeeScript
|
|
DBTYPE = 'SQLite' # OR "MySQL"
|
|
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')
|
|
coffeescript = require('coffee-script/register')
|
|
|
|
app = express()
|
|
|
|
|
|
# /**
|
|
# * Configuration
|
|
# */
|
|
if DBTYPE == "MySQL"
|
|
mysql = require('mysql');
|
|
db_config =
|
|
host: 'localhost',
|
|
user: 'website',
|
|
password: 'henrypump'
|
|
handleDisconnect = () ->
|
|
console.log "Handling db disconnect gracefully"
|
|
app.locals.connection = mysql.createConnection db_config
|
|
app.locals.connection.connect (err) ->
|
|
if err
|
|
console.log 'error when connecting to db:', err
|
|
setTimeout handleDisconnect, 2000
|
|
app.locals.connection.on 'error', (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.coffee');
|
|
|
|
app.set 'port', process.env.PORT || 3000
|
|
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 '/bower_components', express.static __dirname + '/bower_components'
|
|
app.use '/node_modules', express.static __dirname + '/node_modules'
|
|
|
|
# /**
|
|
# * Routes
|
|
# */
|
|
|
|
angular = (req, res) ->
|
|
res.render 'angularIndex'
|
|
undefined
|
|
|
|
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/latestCard/:num', json.latestCardData
|
|
app.get '/json/latestCard', json.latestCardData
|
|
app.get '/json/latest/:num', json.cardLatestX
|
|
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
|
|
|
|
# //-- Tag Values -- //
|
|
app.get '/json/tagvalues', json.getTagValues
|
|
app.get '/json/tagvalues/:unixTS', json.getValuesClosestTo
|
|
|
|
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
|
|
|
|
|
|
|
|
app.get '*', angular
|
|
|
|
# /**
|
|
# * Start Server
|
|
# */
|
|
|
|
connectionsArray = []
|
|
|
|
s_port = 3000
|
|
|
|
server = app.listen s_port, () ->
|
|
host = server.address().address
|
|
port = server.address().port
|
|
|
|
console.log 'POConsole listening at http://%s:%s', host, port
|
|
console.log "Database Type is %s", DBTYPE
|