Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
A
augustctl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
open-source
augustctl
Commits
316b1078
Verified
Commit
316b1078
authored
Aug 27, 2016
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganization and inline doc
parent
6b58e90e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
21 deletions
+37
-21
server.js
server.js
+37
-21
No files found.
server.js
View file @
316b1078
'
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment