2
2
* @namespace resources
3
3
* @author Mike Amundsen (@mamund)
4
4
* @created 2020-02-01
5
- * @description
6
- * darrt resources
5
+ * @description darrt resources.
7
6
*/
8
7
9
8
/*******************************************
10
9
// initialization and setup for DARRT
11
10
********************************************/
12
11
var express , router , bodyParser , actions , representation ,
13
- transitions , utils , templates , forms , metadata ;
12
+ transitions , utils , templates , forms , metadata
14
13
15
- init ( ) ;
14
+ init ( )
16
15
17
16
// shared metadata for this service
18
17
metadata = [
@@ -21,9 +20,9 @@ metadata = [
21
20
{ name : "release" , value : "1.0.0" } ,
22
21
{ name : "generated" , value : "{date}" } ,
23
22
{ name : "url" , value : "{fullhost}" }
24
- ] ;
23
+ ]
25
24
26
- router . use ( timeLog ) ;
25
+ router . use ( timeLog )
27
26
28
27
/**
29
28
* @memberof resources
@@ -35,23 +34,23 @@ router.use(timeLog);
35
34
* optional tracking middleware
36
35
*/
37
36
function timeLog ( req , res , next ) {
38
- console . log ( 'Time: ' , Date . now ( ) + " : " + req . headers . host + req . url + " : " + req . method + " : " + JSON . stringify ( req . body ) ) ;
39
- next ( ) ;
37
+ console . log ( 'Time: ' , Date . now ( ) + " : " + req . headers . host + req . url + " : " + req . method + " : " + JSON . stringify ( req . body ) )
38
+ next ( )
40
39
}
41
40
42
41
/************************************************************************/
43
42
44
43
// ***********************************************************
45
44
// public resources for the api service
46
45
// ***********************************************************
47
- router . get ( '/' , routerCallback ( actions . home , 'home' , 'home' ) ) ;
48
- router . post ( '/' , routerCallback ( actions . create , 'api' , 'list' ) ) ;
49
- router . get ( '/list/' , routerCallback ( actions . list , 'api' , 'list' ) ) ;
50
- router . get ( '/filter/' , routerCallback ( actions . filter , 'api' , 'list' ) ) ;
51
- router . get ( '/:id' , routerCallback ( actions . read , 'api' , 'item' ) ) ;
52
- router . put ( '/:id' , routerCallback ( actions . update , 'api' , 'item' ) ) ;
53
- router . delete ( '/:id' , routerCallback ( actions . remove , 'api' , 'list' ) ) ;
54
- router . patch ( '/status/:id' , routerCallback ( actions . status , 'api' , 'item' ) ) ;
46
+ router . get ( '/' , routerCallback ( actions . home , 'home' , 'home' ) )
47
+ router . post ( '/' , routerCallback ( actions . create , 'api' , 'list' ) )
48
+ router . get ( '/list/' , routerCallback ( actions . list , 'api' , 'list' ) )
49
+ router . get ( '/filter/' , routerCallback ( actions . filter , 'api' , 'list' ) )
50
+ router . get ( '/:id' , routerCallback ( actions . read , 'api' , 'item' ) )
51
+ router . put ( '/:id' , routerCallback ( actions . update , 'api' , 'item' ) )
52
+ router . delete ( '/:id' , routerCallback ( actions . remove , 'api' , 'list' ) )
53
+ router . patch ( '/status/:id' , routerCallback ( actions . status , 'api' , 'item' ) )
55
54
56
55
/**
57
56
* @function routerCallback
@@ -66,19 +65,19 @@ function routerCallback (act, type, filter) {
66
65
* @param {object } res - Express Response object.
67
66
*/
68
67
return function ( req , res ) {
69
- var args = { } ;
70
- args . request = req ;
71
- args . response = res ;
72
- args . action = act ;
73
- args . type = type ;
68
+ var args = { }
69
+ args . request = req
70
+ args . response = res
71
+ args . action = act
72
+ args . type = type
74
73
args . config = {
75
74
metadata : metadata ,
76
75
templates : templates ,
77
76
forms : forms ,
78
77
filter : filter
79
- } ;
80
- respond ( args ) ;
81
- } ;
78
+ }
79
+ respond ( args )
80
+ }
82
81
}
83
82
84
83
/***********************************************************************/
@@ -90,22 +89,22 @@ function routerCallback (act, type, filter) {
90
89
* initialize module
91
90
*/
92
91
function init ( ) {
93
- express = require ( 'express' ) ;
94
- router = express . Router ( ) ;
95
- bodyParser = require ( 'body-parser' ) ;
92
+ express = require ( 'express' )
93
+ router = express . Router ( )
94
+ bodyParser = require ( 'body-parser' )
96
95
97
- actions = require ( './actions' ) ;
98
- representation = require ( './representation' ) ;
99
- transitions = require ( './transitions' ) ;
100
- utils = require ( './lib/utils' ) ;
96
+ actions = require ( './actions' )
97
+ representation = require ( './representation' )
98
+ transitions = require ( './transitions' )
99
+ utils = require ( './lib/utils' )
101
100
102
101
// set up request body parsing & response templates
103
- router . use ( bodyParser . json ( { type : representation . getResponseTypes ( ) } ) ) ;
104
- router . use ( bodyParser . urlencoded ( { extended : representation . urlencoded } ) ) ;
102
+ router . use ( bodyParser . json ( { type : representation . getResponseTypes ( ) } ) )
103
+ router . use ( bodyParser . urlencoded ( { extended : representation . urlencoded } ) )
105
104
106
105
// load response templates and input forms
107
- templates = representation . getTemplates ( ) ;
108
- forms = transitions . forms ;
106
+ templates = representation . getTemplates ( )
107
+ forms = transitions . forms
109
108
}
110
109
111
110
/**
@@ -116,16 +115,16 @@ function init () {
116
115
* local resour5ce handler function
117
116
*/
118
117
function respond ( args ) {
119
- var request = args . request || null ;
120
- var response = args . response || null ;
121
- var action = args . action || null ;
122
- var object = args . type || "" ;
123
- var config = args . config || { } ;
118
+ var request = args . request || null
119
+ var response = args . response || null
120
+ var action = args . action || null
121
+ var object = args . type || ""
122
+ var config = args . config || { }
124
123
125
- return utils . handler ( request , response , action , object , config ) ;
124
+ return utils . handler ( request , response , action , object , config )
126
125
}
127
126
128
127
// publish the capability routes
129
- module . exports = router ;
128
+ module . exports = router
130
129
131
130
// EOF
0 commit comments