From 316b1078ef245f13026fc00624e51cb7195ecce5 Mon Sep 17 00:00:00 2001 From: Erick Hitter <services@ethitter.com> Date: Sat, 27 Aug 2016 20:37:10 -0700 Subject: [PATCH] Reorganization and inline doc --- server.js | 58 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/server.js b/server.js index e33e064..e097e27 100755 --- a/server.js +++ b/server.js @@ -1,5 +1,9 @@ 'use strict'; +/** + * LIBRARIES + */ + var augustctl = require( './index' ); var express = require( 'express' ); var morgan = require( 'morgan' ); @@ -18,6 +22,10 @@ var port = serverConfig.port || 3000; var app = express(); app.use( morgan( DEBUG ? 'dev' : 'combined' ) ); +/** + * UTILITIES + */ + // Default return arguments var ret = { 'status': -1, @@ -25,6 +33,32 @@ var ret = { 'msg': '' }; +// Convert named status to integer representation +function statusStringtoInt( status ) { + var statusInt = -1; + + if ( 'locked' === status ) { + statusInt = 0; + } else if ( 'unlocked' === status ) { + statusInt = 1; + } + + return statusInt; +} + +// Clear cached routes +function clear_caches( lockName ) { + apicache.clear( '/api/status/' + lockName ); + apicache.clear( '/api/lock/' + lockName ); + apicache.clear( '/api/unlock/' + lockName ); + + return true; +} + +/** + * ROUTES + */ + // Endpoint to check lock status app.get( '/api/status/:lock_name', cache( '15 seconds' ), function( req, res ) { // Parse allowed request arguments @@ -125,27 +159,9 @@ app.get( '/api/disconnect/:lock_name', function( req, res ) { res.sendStatus( 204 ); } ); -// Convert named status to integer representation -function statusStringtoInt( status ) { - var statusInt = -1; - - if ( 'locked' === status ) { - statusInt = 0; - } else if ( 'unlocked' === status ) { - statusInt = 1; - } - - return statusInt; -} - -// Clear cached routes -function clear_caches( lockName ) { - apicache.clear( '/api/status/' + lockName ); - apicache.clear( '/api/lock/' + lockName ); - apicache.clear( '/api/unlock/' + lockName ); - - return true; -} +/** + * SERVER SETUP + */ // Parse lock configurations Object.keys( config ).forEach( function( lockName ) { -- GitLab